<!DOCTYPE HTML>
<html lang="zh-CN">


<head>
    <meta charset="utf-8">
    <meta name="keywords" content="gofpdf示例文档, 双的鱼 双的鱼博客 hexo博客 个人博客">
    <meta name="description" content="双的鱼博客，记录我的学习和感想">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=no">
    <meta name="renderer" content="webkit|ie-stand|ie-comp">
    <meta name="mobile-web-app-capable" content="yes">
    <meta name="format-detection" content="telephone=no">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="apple-mobile-web-app-status-bar-style" content="black-translucent">
    <meta name="referrer" content="no-referrer" />
    <!-- Global site tag (gtag.js) - Google Analytics -->


    <title>gofpdf示例文档 | 双的鱼博客</title>
    <link rel="icon" type="image/png" href="/images/logo.png">

    <link rel="stylesheet" type="text/css" href="/libs/awesome/css/all.css">
    <link rel="stylesheet" type="text/css" href="/libs/materialize/materialize.min.css">
    <link rel="stylesheet" type="text/css" href="/libs/aos/aos.css">
    <link rel="stylesheet" type="text/css" href="/libs/animate/animate.min.css">
    <link rel="stylesheet" type="text/css" href="/libs/lightGallery/css/lightgallery.min.css">
    <link rel="stylesheet" type="text/css" href="/css/matery.css">
    <link rel="stylesheet" type="text/css" href="/css/my.css">

    <script src="/libs/jquery/jquery.min.js"></script>

<meta name="generator" content="Hexo 6.3.0"><link rel="alternate" href="/atom.xml" title="双的鱼博客" type="application/atom+xml">
</head>




<body>
    <header class="navbar-fixed">
    <nav id="headNav" class="bg-color nav-transparent">
        <div id="navContainer" class="nav-wrapper container">
            <div class="brand-logo">
                <a href="/" class="waves-effect waves-light">
                    
                    <img src="/images/logo.png" class="logo-img" alt="LOGO">
                    
                    <span class="logo-span">双的鱼博客</span>
                </a>
            </div>
            

<a href="#" data-target="mobile-nav" class="sidenav-trigger button-collapse"><i class="fas fa-bars"></i></a>
<ul class="right nav-menu">
  
  <li class="hide-on-med-and-down nav-item">
    
    <a href="/" class="waves-effect waves-light">
      
      <i class="fas fa-home" style="zoom: 0.6;"></i>
      
      <span>首页</span>
    </a>
    
  </li>
  
  <li class="hide-on-med-and-down nav-item">
    
    <a href="/tags" class="waves-effect waves-light">
      
      <i class="fas fa-tags" style="zoom: 0.6;"></i>
      
      <span>标签</span>
    </a>
    
  </li>
  
  <li class="hide-on-med-and-down nav-item">
    
    <a href="/categories" class="waves-effect waves-light">
      
      <i class="fas fa-bookmark" style="zoom: 0.6;"></i>
      
      <span>分类</span>
    </a>
    
  </li>
  
  <li class="hide-on-med-and-down nav-item">
    
    <a href="/archives" class="waves-effect waves-light">
      
      <i class="fas fa-archive" style="zoom: 0.6;"></i>
      
      <span>归档</span>
    </a>
    
  </li>
  
  <li class="hide-on-med-and-down nav-item">
    
    <a href="/weibo" class="waves-effect waves-light">
      
      <i class="fa fa-comment" style="zoom: 0.6;"></i>
      
      <span>微博</span>
    </a>
    
  </li>
  
  <li class="hide-on-med-and-down nav-item">
    
    <a href="/album" class="waves-effect waves-light">
      
      <i class="fa fa-camera-retro" style="zoom: 0.6;"></i>
      
      <span>相册</span>
    </a>
    
  </li>
  
  <li class="hide-on-med-and-down nav-item">
    
    <a href="/about" class="waves-effect waves-light">
      
      <i class="fas fa-user-circle" style="zoom: 0.6;"></i>
      
      <span>关于</span>
    </a>
    
  </li>
  
  <li>
    <a href="#searchModal" class="modal-trigger waves-effect waves-light">
      <i id="searchIcon" class="fas fa-search" title="搜索" style="zoom: 0.85;"></i>
    </a>
  </li>
</ul>


<div id="mobile-nav" class="side-nav sidenav">

    <div class="mobile-head bg-color">
        
        <img src="/images/logo.png" class="logo-img circle responsive-img">
        
        <div class="logo-name">双的鱼博客</div>
        <div class="logo-desc">
            
            双的鱼博客，记录我的学习和感想
            
        </div>
    </div>

    

    <ul class="menu-list mobile-menu-list">
        
        <li class="m-nav-item">
	  
		<a href="/" class="waves-effect waves-light">
			
			    <i class="fa-fw fas fa-home"></i>
			
			首页
		</a>
          
        </li>
        
        <li class="m-nav-item">
	  
		<a href="/tags" class="waves-effect waves-light">
			
			    <i class="fa-fw fas fa-tags"></i>
			
			标签
		</a>
          
        </li>
        
        <li class="m-nav-item">
	  
		<a href="/categories" class="waves-effect waves-light">
			
			    <i class="fa-fw fas fa-bookmark"></i>
			
			分类
		</a>
          
        </li>
        
        <li class="m-nav-item">
	  
		<a href="/archives" class="waves-effect waves-light">
			
			    <i class="fa-fw fas fa-archive"></i>
			
			归档
		</a>
          
        </li>
        
        <li class="m-nav-item">
	  
		<a href="/weibo" class="waves-effect waves-light">
			
			    <i class="fa-fw fa fa-comment"></i>
			
			微博
		</a>
          
        </li>
        
        <li class="m-nav-item">
	  
		<a href="/album" class="waves-effect waves-light">
			
			    <i class="fa-fw fa fa-camera-retro"></i>
			
			相册
		</a>
          
        </li>
        
        <li class="m-nav-item">
	  
		<a href="/about" class="waves-effect waves-light">
			
			    <i class="fa-fw fas fa-user-circle"></i>
			
			关于
		</a>
          
        </li>
        
        
    </ul>
</div>


        </div>

        
    </nav>

</header>

    
<script src="/libs/cryptojs/crypto-js.min.js"></script>
<script>
    (function() {
        let pwd = '';
        if (pwd && pwd.length > 0) {
            if (pwd !== CryptoJS.SHA256(prompt('请输入访问本文章的密码')).toString(CryptoJS.enc.Hex)) {
                alert('密码错误，将返回主页！');
                location.href = '/';
            }
        }
    })();
</script>




<div class="bg-cover pd-header post-cover" style="background-image: url('/gallery/gofpdf.jpg')">
    <div class="container" style="right: 0px;left: 0px;">
        <div class="row">
            <div class="col s12 m12 l12">
                <div class="brand">
                    <h1 class="description center-align post-title">gofpdf示例文档</h1>
                </div>
            </div>
        </div>
    </div>
</div>




<main class="post-container content">

    
    <link rel="stylesheet" href="/libs/tocbot/tocbot.css">
<style>
    #articleContent h1::before,
    #articleContent h2::before,
    #articleContent h3::before,
    #articleContent h4::before,
    #articleContent h5::before,
    #articleContent h6::before {
        display: block;
        content: " ";
        height: 100px;
        margin-top: -100px;
        visibility: hidden;
    }

    #articleContent :focus {
        outline: none;
    }

    .toc-fixed {
        position: fixed;
        top: 64px;
    }

    .toc-widget {
        width: 345px;
        padding-left: 20px;
        height: auto;
    }

    .toc-widget .toc-title {
        padding: 35px 0 15px 17px;
        font-size: 1.5rem;
        font-weight: bold;
        line-height: 1.5rem;
    }

    .toc-widget ol {
        padding: 0;
        list-style: none;
    }

    #toc-content {
        padding-bottom: 30px;
        overflow: auto;
        max-height: calc(100vh - 10rem);
    }

    #toc-content ol {
        padding-left: 10px;
        overflow: auto;
    }

    #toc-content ol li {
        padding-left: 10px;
    }

    #toc-content .toc-link:hover {
        color: #42b983;
        font-weight: 700;
        text-decoration: underline;
    }

    #toc-content .toc-link::before {
        background-color: transparent;
        max-height: 25px;

        position: absolute;
        right: 23.5vw;
        display: block;
    }

    #toc-content .is-active-link {
        color: #42b983;
    }

    #floating-toc-btn {
        position: fixed;
        right: 15px;
        bottom: 76px;
        padding-top: 15px;
        margin-bottom: 0;
        z-index: 998;
    }

    #floating-toc-btn .btn-floating {
        width: 48px;
        height: 48px;
    }

    #floating-toc-btn .btn-floating i {
        line-height: 48px;
        font-size: 1.4rem;
    }
</style>
<div class="row">
    <div id="main-content" class="col s12 m12 l9">
        <!-- 文章内容详情 -->
<div id="artDetail">
    <div class="card">
        <div class="card-content article-info">
            <div class="row tag-cate">
                <div class="col s7">
                    
                    <div class="article-tag">
                        
                            <a href="/tags/Go/">
                                <span class="chip bg-color">Go</span>
                            </a>
                        
                            <a href="/tags/PDF/">
                                <span class="chip bg-color">PDF</span>
                            </a>
                        
                    </div>
                    
                </div>
                <div class="col s5 right-align">
                    
                    <div class="post-cate">
                        <i class="fas fa-bookmark fa-fw icon-category"></i>
                        
                            <a href="/categories/%E6%8A%80%E6%9C%AF/" class="post-category">
                                技术
                            </a>
                        
                    </div>
                    
                </div>
            </div>

            <div class="post-info">
                
                <div class="post-date info-break-policy">
                    <i class="far fa-calendar-minus fa-fw"></i>发布日期:&nbsp;&nbsp;
                    2024-01-30
                </div>
                

                

                
                <div class="info-break-policy">
                    <i class="far fa-file-word fa-fw"></i>文章字数:&nbsp;&nbsp;
                    12k
                </div>
                

                
                <div class="info-break-policy">
                    <i class="far fa-clock fa-fw"></i>阅读时长:&nbsp;&nbsp;
                    71 分
                </div>
                

                
            </div>
        </div>
        <hr class="clearfix">

        
        <!-- 是否加载使用自带的 prismjs. -->
        <link rel="stylesheet" href="/libs/prism/prism.css">
        

        

        <div class="card-content article-card-content">
            <div id="articleContent">
                <p>最近在做Golang创建PDF方面的项目，一通找寻后主要定位到了两个现成的PDF库，也是网上比较流行的直接引用库，一个是<a target="_blank" rel="noopener" href="https://github.com/signintech/gopdf">gopdf</a>，另一个是<a target="_blank" rel="noopener" href="https://github.com/jung-kurt/gofpdf/tree/master">gofpdf</a></p>
<p>这两个库基本功能大致相同，都包含了常用的一些PDF功能，但还是有一些区别，正是这些区别导致我选择了<strong>gofpdf</strong></p>
<p><strong>gofpdf</strong> 已经归档了，不再更新，而 <strong>gopdf</strong> 还在更新中，但更新速度也是比较缓慢的，最近一次更新还是两个月前</p>
<p>而 <strong>gofpdf</strong> 对字体样式的支持更加丰富，能够设置加粗，斜体等功能，所以我的项目中选择了它，不过它的文档不够丰富，所以我翻译了下它test文件里面的代码，当做一个示例查询目录，使用的时候方便点</p>
<h2 id="基础"><a href="#基础" class="headerlink" title="基础"></a>基础</h2><pre class="language-go" data-language="go"><code class="language-go"><span class="token keyword">func</span> <span class="token function">Example</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">&#123;</span>
	pdf <span class="token operator">:=</span> gofpdf<span class="token punctuation">.</span><span class="token function">New</span><span class="token punctuation">(</span>gofpdf<span class="token punctuation">.</span>OrientationPortrait<span class="token punctuation">,</span> <span class="token string">"mm"</span><span class="token punctuation">,</span> <span class="token string">"A4"</span><span class="token punctuation">,</span> <span class="token string">""</span><span class="token punctuation">)</span>
	pdf<span class="token punctuation">.</span><span class="token function">AddPage</span><span class="token punctuation">(</span><span class="token punctuation">)</span>
	pdf<span class="token punctuation">.</span><span class="token function">SetFont</span><span class="token punctuation">(</span><span class="token string">"Arial"</span><span class="token punctuation">,</span> <span class="token string">"B"</span><span class="token punctuation">,</span> <span class="token number">16</span><span class="token punctuation">)</span>
	pdf<span class="token punctuation">.</span><span class="token function">Cell</span><span class="token punctuation">(</span><span class="token number">40</span><span class="token punctuation">,</span> <span class="token number">10</span><span class="token punctuation">,</span> <span class="token string">"Hello World!"</span><span class="token punctuation">)</span>
	fileStr <span class="token operator">:=</span> example<span class="token punctuation">.</span><span class="token function">Filename</span><span class="token punctuation">(</span><span class="token string">"basic"</span><span class="token punctuation">)</span>
	err <span class="token operator">:=</span> pdf<span class="token punctuation">.</span><span class="token function">OutputFileAndClose</span><span class="token punctuation">(</span>fileStr<span class="token punctuation">)</span>
	example<span class="token punctuation">.</span><span class="token function">Summary</span><span class="token punctuation">(</span>err<span class="token punctuation">,</span> fileStr<span class="token punctuation">)</span>
	<span class="token comment">// Output:</span>
	<span class="token comment">// Successfully generated pdf/basic.pdf</span>
<span class="token punctuation">&#125;</span></code></pre>

<h2 id="演示页眉、页脚和分页符的生成"><a href="#演示页眉、页脚和分页符的生成" class="headerlink" title="演示页眉、页脚和分页符的生成"></a>演示页眉、页脚和分页符的生成</h2><pre class="language-go" data-language="go"><code class="language-go"><span class="token comment">// ExampleFpdf_AddPage demonsrates the generation of headers, footers and page breaks.</span>
<span class="token keyword">func</span> <span class="token function">ExampleFpdf_AddPage</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">&#123;</span>
	pdf <span class="token operator">:=</span> gofpdf<span class="token punctuation">.</span><span class="token function">New</span><span class="token punctuation">(</span><span class="token string">"P"</span><span class="token punctuation">,</span> <span class="token string">"mm"</span><span class="token punctuation">,</span> <span class="token string">"A4"</span><span class="token punctuation">,</span> <span class="token string">""</span><span class="token punctuation">)</span>
	pdf<span class="token punctuation">.</span><span class="token function">SetTopMargin</span><span class="token punctuation">(</span><span class="token number">30</span><span class="token punctuation">)</span>
	pdf<span class="token punctuation">.</span><span class="token function">SetHeaderFuncMode</span><span class="token punctuation">(</span><span class="token keyword">func</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">&#123;</span>
		pdf<span class="token punctuation">.</span><span class="token function">Image</span><span class="token punctuation">(</span>example<span class="token punctuation">.</span><span class="token function">ImageFile</span><span class="token punctuation">(</span><span class="token string">"logo.png"</span><span class="token punctuation">)</span><span class="token punctuation">,</span> <span class="token number">10</span><span class="token punctuation">,</span> <span class="token number">6</span><span class="token punctuation">,</span> <span class="token number">30</span><span class="token punctuation">,</span> <span class="token number">0</span><span class="token punctuation">,</span> <span class="token boolean">false</span><span class="token punctuation">,</span> <span class="token string">""</span><span class="token punctuation">,</span> <span class="token number">0</span><span class="token punctuation">,</span> <span class="token string">""</span><span class="token punctuation">)</span>
		pdf<span class="token punctuation">.</span><span class="token function">SetY</span><span class="token punctuation">(</span><span class="token number">5</span><span class="token punctuation">)</span>
		pdf<span class="token punctuation">.</span><span class="token function">SetFont</span><span class="token punctuation">(</span><span class="token string">"Arial"</span><span class="token punctuation">,</span> <span class="token string">"B"</span><span class="token punctuation">,</span> <span class="token number">15</span><span class="token punctuation">)</span>
		pdf<span class="token punctuation">.</span><span class="token function">Cell</span><span class="token punctuation">(</span><span class="token number">80</span><span class="token punctuation">,</span> <span class="token number">0</span><span class="token punctuation">,</span> <span class="token string">""</span><span class="token punctuation">)</span>
		pdf<span class="token punctuation">.</span><span class="token function">CellFormat</span><span class="token punctuation">(</span><span class="token number">30</span><span class="token punctuation">,</span> <span class="token number">10</span><span class="token punctuation">,</span> <span class="token string">"Title"</span><span class="token punctuation">,</span> <span class="token string">"1"</span><span class="token punctuation">,</span> <span class="token number">0</span><span class="token punctuation">,</span> <span class="token string">"C"</span><span class="token punctuation">,</span> <span class="token boolean">false</span><span class="token punctuation">,</span> <span class="token number">0</span><span class="token punctuation">,</span> <span class="token string">""</span><span class="token punctuation">)</span>
		pdf<span class="token punctuation">.</span><span class="token function">Ln</span><span class="token punctuation">(</span><span class="token number">20</span><span class="token punctuation">)</span>
	<span class="token punctuation">&#125;</span><span class="token punctuation">,</span> <span class="token boolean">true</span><span class="token punctuation">)</span>
	pdf<span class="token punctuation">.</span><span class="token function">SetFooterFunc</span><span class="token punctuation">(</span><span class="token keyword">func</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">&#123;</span>
		pdf<span class="token punctuation">.</span><span class="token function">SetY</span><span class="token punctuation">(</span><span class="token operator">-</span><span class="token number">15</span><span class="token punctuation">)</span>
		pdf<span class="token punctuation">.</span><span class="token function">SetFont</span><span class="token punctuation">(</span><span class="token string">"Arial"</span><span class="token punctuation">,</span> <span class="token string">"I"</span><span class="token punctuation">,</span> <span class="token number">8</span><span class="token punctuation">)</span>
		pdf<span class="token punctuation">.</span><span class="token function">CellFormat</span><span class="token punctuation">(</span><span class="token number">0</span><span class="token punctuation">,</span> <span class="token number">10</span><span class="token punctuation">,</span> fmt<span class="token punctuation">.</span><span class="token function">Sprintf</span><span class="token punctuation">(</span><span class="token string">"Page %d/&#123;nb&#125;"</span><span class="token punctuation">,</span> pdf<span class="token punctuation">.</span><span class="token function">PageNo</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">,</span>
			<span class="token string">""</span><span class="token punctuation">,</span> <span class="token number">0</span><span class="token punctuation">,</span> <span class="token string">"C"</span><span class="token punctuation">,</span> <span class="token boolean">false</span><span class="token punctuation">,</span> <span class="token number">0</span><span class="token punctuation">,</span> <span class="token string">""</span><span class="token punctuation">)</span>
	<span class="token punctuation">&#125;</span><span class="token punctuation">)</span>
	pdf<span class="token punctuation">.</span><span class="token function">AliasNbPages</span><span class="token punctuation">(</span><span class="token string">""</span><span class="token punctuation">)</span>
	pdf<span class="token punctuation">.</span><span class="token function">AddPage</span><span class="token punctuation">(</span><span class="token punctuation">)</span>
	pdf<span class="token punctuation">.</span><span class="token function">SetFont</span><span class="token punctuation">(</span><span class="token string">"Times"</span><span class="token punctuation">,</span> <span class="token string">""</span><span class="token punctuation">,</span> <span class="token number">12</span><span class="token punctuation">)</span>
	<span class="token keyword">for</span> j <span class="token operator">:=</span> <span class="token number">1</span><span class="token punctuation">;</span> j <span class="token operator">&lt;=</span> <span class="token number">40</span><span class="token punctuation">;</span> j<span class="token operator">++</span> <span class="token punctuation">&#123;</span>
		pdf<span class="token punctuation">.</span><span class="token function">CellFormat</span><span class="token punctuation">(</span><span class="token number">0</span><span class="token punctuation">,</span> <span class="token number">10</span><span class="token punctuation">,</span> fmt<span class="token punctuation">.</span><span class="token function">Sprintf</span><span class="token punctuation">(</span><span class="token string">"Printing line number %d"</span><span class="token punctuation">,</span> j<span class="token punctuation">)</span><span class="token punctuation">,</span>
			<span class="token string">""</span><span class="token punctuation">,</span> <span class="token number">1</span><span class="token punctuation">,</span> <span class="token string">""</span><span class="token punctuation">,</span> <span class="token boolean">false</span><span class="token punctuation">,</span> <span class="token number">0</span><span class="token punctuation">,</span> <span class="token string">""</span><span class="token punctuation">)</span>
	<span class="token punctuation">&#125;</span>
	fileStr <span class="token operator">:=</span> example<span class="token punctuation">.</span><span class="token function">Filename</span><span class="token punctuation">(</span><span class="token string">"Fpdf_AddPage"</span><span class="token punctuation">)</span>
	err <span class="token operator">:=</span> pdf<span class="token punctuation">.</span><span class="token function">OutputFileAndClose</span><span class="token punctuation">(</span>fileStr<span class="token punctuation">)</span>
	example<span class="token punctuation">.</span><span class="token function">Summary</span><span class="token punctuation">(</span>err<span class="token punctuation">,</span> fileStr<span class="token punctuation">)</span>
	<span class="token comment">// Output:</span>
	<span class="token comment">// Successfully generated pdf/Fpdf_AddPage.pdf</span>
<span class="token punctuation">&#125;</span></code></pre>

<h2 id="演示换行、行对齐和分页"><a href="#演示换行、行对齐和分页" class="headerlink" title="演示换行、行对齐和分页"></a>演示换行、行对齐和分页</h2><pre class="language-go" data-language="go"><code class="language-go"><span class="token comment">// ExampleFpdf_MultiCell demonstrates word-wrapping, line justification and</span>
<span class="token comment">// page-breaking.</span>
<span class="token keyword">func</span> <span class="token function">ExampleFpdf_MultiCell</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">&#123;</span>
	pdf <span class="token operator">:=</span> gofpdf<span class="token punctuation">.</span><span class="token function">New</span><span class="token punctuation">(</span><span class="token string">"P"</span><span class="token punctuation">,</span> <span class="token string">"mm"</span><span class="token punctuation">,</span> <span class="token string">"A4"</span><span class="token punctuation">,</span> <span class="token string">""</span><span class="token punctuation">)</span>
	titleStr <span class="token operator">:=</span> <span class="token string">"20000 Leagues Under the Seas"</span>
	pdf<span class="token punctuation">.</span><span class="token function">SetTitle</span><span class="token punctuation">(</span>titleStr<span class="token punctuation">,</span> <span class="token boolean">false</span><span class="token punctuation">)</span>
	pdf<span class="token punctuation">.</span><span class="token function">SetAuthor</span><span class="token punctuation">(</span><span class="token string">"Jules Verne"</span><span class="token punctuation">,</span> <span class="token boolean">false</span><span class="token punctuation">)</span>
	pdf<span class="token punctuation">.</span><span class="token function">SetHeaderFunc</span><span class="token punctuation">(</span><span class="token keyword">func</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">&#123;</span>
		<span class="token comment">// Arial bold 15</span>
		pdf<span class="token punctuation">.</span><span class="token function">SetFont</span><span class="token punctuation">(</span><span class="token string">"Arial"</span><span class="token punctuation">,</span> <span class="token string">"B"</span><span class="token punctuation">,</span> <span class="token number">15</span><span class="token punctuation">)</span>
		<span class="token comment">// Calculate width of title and position</span>
		wd <span class="token operator">:=</span> pdf<span class="token punctuation">.</span><span class="token function">GetStringWidth</span><span class="token punctuation">(</span>titleStr<span class="token punctuation">)</span> <span class="token operator">+</span> <span class="token number">6</span>
		pdf<span class="token punctuation">.</span><span class="token function">SetX</span><span class="token punctuation">(</span><span class="token punctuation">(</span><span class="token number">210</span> <span class="token operator">-</span> wd<span class="token punctuation">)</span> <span class="token operator">/</span> <span class="token number">2</span><span class="token punctuation">)</span>
		<span class="token comment">// Colors of frame, background and text</span>
		pdf<span class="token punctuation">.</span><span class="token function">SetDrawColor</span><span class="token punctuation">(</span><span class="token number">0</span><span class="token punctuation">,</span> <span class="token number">80</span><span class="token punctuation">,</span> <span class="token number">180</span><span class="token punctuation">)</span>
		pdf<span class="token punctuation">.</span><span class="token function">SetFillColor</span><span class="token punctuation">(</span><span class="token number">230</span><span class="token punctuation">,</span> <span class="token number">230</span><span class="token punctuation">,</span> <span class="token number">0</span><span class="token punctuation">)</span>
		pdf<span class="token punctuation">.</span><span class="token function">SetTextColor</span><span class="token punctuation">(</span><span class="token number">220</span><span class="token punctuation">,</span> <span class="token number">50</span><span class="token punctuation">,</span> <span class="token number">50</span><span class="token punctuation">)</span>
		<span class="token comment">// Thickness of frame (1 mm)</span>
		pdf<span class="token punctuation">.</span><span class="token function">SetLineWidth</span><span class="token punctuation">(</span><span class="token number">1</span><span class="token punctuation">)</span>
		<span class="token comment">// Title</span>
		pdf<span class="token punctuation">.</span><span class="token function">CellFormat</span><span class="token punctuation">(</span>wd<span class="token punctuation">,</span> <span class="token number">9</span><span class="token punctuation">,</span> titleStr<span class="token punctuation">,</span> <span class="token string">"1"</span><span class="token punctuation">,</span> <span class="token number">1</span><span class="token punctuation">,</span> <span class="token string">"C"</span><span class="token punctuation">,</span> <span class="token boolean">true</span><span class="token punctuation">,</span> <span class="token number">0</span><span class="token punctuation">,</span> <span class="token string">""</span><span class="token punctuation">)</span>
		<span class="token comment">// Line break</span>
		pdf<span class="token punctuation">.</span><span class="token function">Ln</span><span class="token punctuation">(</span><span class="token number">10</span><span class="token punctuation">)</span>
	<span class="token punctuation">&#125;</span><span class="token punctuation">)</span>
	pdf<span class="token punctuation">.</span><span class="token function">SetFooterFunc</span><span class="token punctuation">(</span><span class="token keyword">func</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">&#123;</span>
		<span class="token comment">// Position at 1.5 cm from bottom</span>
		pdf<span class="token punctuation">.</span><span class="token function">SetY</span><span class="token punctuation">(</span><span class="token operator">-</span><span class="token number">15</span><span class="token punctuation">)</span>
		<span class="token comment">// Arial italic 8</span>
		pdf<span class="token punctuation">.</span><span class="token function">SetFont</span><span class="token punctuation">(</span><span class="token string">"Arial"</span><span class="token punctuation">,</span> <span class="token string">"I"</span><span class="token punctuation">,</span> <span class="token number">8</span><span class="token punctuation">)</span>
		<span class="token comment">// Text color in gray</span>
		pdf<span class="token punctuation">.</span><span class="token function">SetTextColor</span><span class="token punctuation">(</span><span class="token number">128</span><span class="token punctuation">,</span> <span class="token number">128</span><span class="token punctuation">,</span> <span class="token number">128</span><span class="token punctuation">)</span>
		<span class="token comment">// Page number</span>
		pdf<span class="token punctuation">.</span><span class="token function">CellFormat</span><span class="token punctuation">(</span><span class="token number">0</span><span class="token punctuation">,</span> <span class="token number">10</span><span class="token punctuation">,</span> fmt<span class="token punctuation">.</span><span class="token function">Sprintf</span><span class="token punctuation">(</span><span class="token string">"Page %d"</span><span class="token punctuation">,</span> pdf<span class="token punctuation">.</span><span class="token function">PageNo</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">,</span>
			<span class="token string">""</span><span class="token punctuation">,</span> <span class="token number">0</span><span class="token punctuation">,</span> <span class="token string">"C"</span><span class="token punctuation">,</span> <span class="token boolean">false</span><span class="token punctuation">,</span> <span class="token number">0</span><span class="token punctuation">,</span> <span class="token string">""</span><span class="token punctuation">)</span>
	<span class="token punctuation">&#125;</span><span class="token punctuation">)</span>
	chapterTitle <span class="token operator">:=</span> <span class="token keyword">func</span><span class="token punctuation">(</span>chapNum <span class="token builtin">int</span><span class="token punctuation">,</span> titleStr <span class="token builtin">string</span><span class="token punctuation">)</span> <span class="token punctuation">&#123;</span>
		<span class="token comment">// 	// Arial 12</span>
		pdf<span class="token punctuation">.</span><span class="token function">SetFont</span><span class="token punctuation">(</span><span class="token string">"Arial"</span><span class="token punctuation">,</span> <span class="token string">""</span><span class="token punctuation">,</span> <span class="token number">12</span><span class="token punctuation">)</span>
		<span class="token comment">// Background color</span>
		pdf<span class="token punctuation">.</span><span class="token function">SetFillColor</span><span class="token punctuation">(</span><span class="token number">200</span><span class="token punctuation">,</span> <span class="token number">220</span><span class="token punctuation">,</span> <span class="token number">255</span><span class="token punctuation">)</span>
		<span class="token comment">// Title</span>
		pdf<span class="token punctuation">.</span><span class="token function">CellFormat</span><span class="token punctuation">(</span><span class="token number">0</span><span class="token punctuation">,</span> <span class="token number">6</span><span class="token punctuation">,</span> fmt<span class="token punctuation">.</span><span class="token function">Sprintf</span><span class="token punctuation">(</span><span class="token string">"Chapter %d : %s"</span><span class="token punctuation">,</span> chapNum<span class="token punctuation">,</span> titleStr<span class="token punctuation">)</span><span class="token punctuation">,</span>
			<span class="token string">""</span><span class="token punctuation">,</span> <span class="token number">1</span><span class="token punctuation">,</span> <span class="token string">"L"</span><span class="token punctuation">,</span> <span class="token boolean">true</span><span class="token punctuation">,</span> <span class="token number">0</span><span class="token punctuation">,</span> <span class="token string">""</span><span class="token punctuation">)</span>
		<span class="token comment">// Line break</span>
		pdf<span class="token punctuation">.</span><span class="token function">Ln</span><span class="token punctuation">(</span><span class="token number">4</span><span class="token punctuation">)</span>
	<span class="token punctuation">&#125;</span>
	chapterBody <span class="token operator">:=</span> <span class="token keyword">func</span><span class="token punctuation">(</span>fileStr <span class="token builtin">string</span><span class="token punctuation">)</span> <span class="token punctuation">&#123;</span>
		<span class="token comment">// Read text file</span>
		txtStr<span class="token punctuation">,</span> err <span class="token operator">:=</span> ioutil<span class="token punctuation">.</span><span class="token function">ReadFile</span><span class="token punctuation">(</span>fileStr<span class="token punctuation">)</span>
		<span class="token keyword">if</span> err <span class="token operator">!=</span> <span class="token boolean">nil</span> <span class="token punctuation">&#123;</span>
			pdf<span class="token punctuation">.</span><span class="token function">SetError</span><span class="token punctuation">(</span>err<span class="token punctuation">)</span>
		<span class="token punctuation">&#125;</span>
		<span class="token comment">// Times 12</span>
		pdf<span class="token punctuation">.</span><span class="token function">SetFont</span><span class="token punctuation">(</span><span class="token string">"Times"</span><span class="token punctuation">,</span> <span class="token string">""</span><span class="token punctuation">,</span> <span class="token number">12</span><span class="token punctuation">)</span>
		<span class="token comment">// Output justified text</span>
		pdf<span class="token punctuation">.</span><span class="token function">MultiCell</span><span class="token punctuation">(</span><span class="token number">0</span><span class="token punctuation">,</span> <span class="token number">5</span><span class="token punctuation">,</span> <span class="token function">string</span><span class="token punctuation">(</span>txtStr<span class="token punctuation">)</span><span class="token punctuation">,</span> <span class="token string">""</span><span class="token punctuation">,</span> <span class="token string">""</span><span class="token punctuation">,</span> <span class="token boolean">false</span><span class="token punctuation">)</span>
		<span class="token comment">// Line break</span>
		pdf<span class="token punctuation">.</span><span class="token function">Ln</span><span class="token punctuation">(</span><span class="token operator">-</span><span class="token number">1</span><span class="token punctuation">)</span>
		<span class="token comment">// Mention in italics</span>
		pdf<span class="token punctuation">.</span><span class="token function">SetFont</span><span class="token punctuation">(</span><span class="token string">""</span><span class="token punctuation">,</span> <span class="token string">"I"</span><span class="token punctuation">,</span> <span class="token number">0</span><span class="token punctuation">)</span>
		pdf<span class="token punctuation">.</span><span class="token function">Cell</span><span class="token punctuation">(</span><span class="token number">0</span><span class="token punctuation">,</span> <span class="token number">5</span><span class="token punctuation">,</span> <span class="token string">"(end of excerpt)"</span><span class="token punctuation">)</span>
	<span class="token punctuation">&#125;</span>
	printChapter <span class="token operator">:=</span> <span class="token keyword">func</span><span class="token punctuation">(</span>chapNum <span class="token builtin">int</span><span class="token punctuation">,</span> titleStr<span class="token punctuation">,</span> fileStr <span class="token builtin">string</span><span class="token punctuation">)</span> <span class="token punctuation">&#123;</span>
		pdf<span class="token punctuation">.</span><span class="token function">AddPage</span><span class="token punctuation">(</span><span class="token punctuation">)</span>
		<span class="token function">chapterTitle</span><span class="token punctuation">(</span>chapNum<span class="token punctuation">,</span> titleStr<span class="token punctuation">)</span>
		<span class="token function">chapterBody</span><span class="token punctuation">(</span>fileStr<span class="token punctuation">)</span>
	<span class="token punctuation">&#125;</span>
	<span class="token function">printChapter</span><span class="token punctuation">(</span><span class="token number">1</span><span class="token punctuation">,</span> <span class="token string">"A RUNAWAY REEF"</span><span class="token punctuation">,</span> example<span class="token punctuation">.</span><span class="token function">TextFile</span><span class="token punctuation">(</span><span class="token string">"20k_c1.txt"</span><span class="token punctuation">)</span><span class="token punctuation">)</span>
	<span class="token function">printChapter</span><span class="token punctuation">(</span><span class="token number">2</span><span class="token punctuation">,</span> <span class="token string">"THE PROS AND CONS"</span><span class="token punctuation">,</span> example<span class="token punctuation">.</span><span class="token function">TextFile</span><span class="token punctuation">(</span><span class="token string">"20k_c2.txt"</span><span class="token punctuation">)</span><span class="token punctuation">)</span>
	fileStr <span class="token operator">:=</span> example<span class="token punctuation">.</span><span class="token function">Filename</span><span class="token punctuation">(</span><span class="token string">"Fpdf_MultiCell"</span><span class="token punctuation">)</span>
	err <span class="token operator">:=</span> pdf<span class="token punctuation">.</span><span class="token function">OutputFileAndClose</span><span class="token punctuation">(</span>fileStr<span class="token punctuation">)</span>
	example<span class="token punctuation">.</span><span class="token function">Summary</span><span class="token punctuation">(</span>err<span class="token punctuation">,</span> fileStr<span class="token punctuation">)</span>
	<span class="token comment">// Output:</span>
	<span class="token comment">// Successfully generated pdf/Fpdf_MultiCell.pdf</span>
<span class="token punctuation">&#125;</span></code></pre>

<h2 id="演示如何生成具有多列的PDF文档"><a href="#演示如何生成具有多列的PDF文档" class="headerlink" title="演示如何生成具有多列的PDF文档"></a>演示如何生成具有多列的PDF文档</h2><p>这是通过SetLeftMargin()和Cell()方法完成的</p>
<pre class="language-go" data-language="go"><code class="language-go"><span class="token comment">// ExampleFpdf_SetLeftMargin demonstrates the generation of a PDF document that has multiple</span>
<span class="token comment">// columns. This is accomplished with the SetLeftMargin() and Cell() methods.</span>
<span class="token keyword">func</span> <span class="token function">ExampleFpdf_SetLeftMargin</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">&#123;</span>
	<span class="token keyword">var</span> y0 <span class="token builtin">float64</span>
	<span class="token keyword">var</span> crrntCol <span class="token builtin">int</span>
	pdf <span class="token operator">:=</span> gofpdf<span class="token punctuation">.</span><span class="token function">New</span><span class="token punctuation">(</span><span class="token string">"P"</span><span class="token punctuation">,</span> <span class="token string">"mm"</span><span class="token punctuation">,</span> <span class="token string">"A4"</span><span class="token punctuation">,</span> <span class="token string">""</span><span class="token punctuation">)</span>
	pdf<span class="token punctuation">.</span><span class="token function">SetDisplayMode</span><span class="token punctuation">(</span><span class="token string">"fullpage"</span><span class="token punctuation">,</span> <span class="token string">"TwoColumnLeft"</span><span class="token punctuation">)</span>
	titleStr <span class="token operator">:=</span> <span class="token string">"20000 Leagues Under the Seas"</span>
	pdf<span class="token punctuation">.</span><span class="token function">SetTitle</span><span class="token punctuation">(</span>titleStr<span class="token punctuation">,</span> <span class="token boolean">false</span><span class="token punctuation">)</span>
	pdf<span class="token punctuation">.</span><span class="token function">SetAuthor</span><span class="token punctuation">(</span><span class="token string">"Jules Verne"</span><span class="token punctuation">,</span> <span class="token boolean">false</span><span class="token punctuation">)</span>
	setCol <span class="token operator">:=</span> <span class="token keyword">func</span><span class="token punctuation">(</span>col <span class="token builtin">int</span><span class="token punctuation">)</span> <span class="token punctuation">&#123;</span>
		<span class="token comment">// Set position at a given column</span>
		crrntCol <span class="token operator">=</span> col
		x <span class="token operator">:=</span> <span class="token number">10.0</span> <span class="token operator">+</span> <span class="token function">float64</span><span class="token punctuation">(</span>col<span class="token punctuation">)</span><span class="token operator">*</span><span class="token number">65.0</span>
		pdf<span class="token punctuation">.</span><span class="token function">SetLeftMargin</span><span class="token punctuation">(</span>x<span class="token punctuation">)</span>
		pdf<span class="token punctuation">.</span><span class="token function">SetX</span><span class="token punctuation">(</span>x<span class="token punctuation">)</span>
	<span class="token punctuation">&#125;</span>
	chapterTitle <span class="token operator">:=</span> <span class="token keyword">func</span><span class="token punctuation">(</span>chapNum <span class="token builtin">int</span><span class="token punctuation">,</span> titleStr <span class="token builtin">string</span><span class="token punctuation">)</span> <span class="token punctuation">&#123;</span>
		<span class="token comment">// Arial 12</span>
		pdf<span class="token punctuation">.</span><span class="token function">SetFont</span><span class="token punctuation">(</span><span class="token string">"Arial"</span><span class="token punctuation">,</span> <span class="token string">""</span><span class="token punctuation">,</span> <span class="token number">12</span><span class="token punctuation">)</span>
		<span class="token comment">// Background color</span>
		pdf<span class="token punctuation">.</span><span class="token function">SetFillColor</span><span class="token punctuation">(</span><span class="token number">200</span><span class="token punctuation">,</span> <span class="token number">220</span><span class="token punctuation">,</span> <span class="token number">255</span><span class="token punctuation">)</span>
		<span class="token comment">// Title</span>
		pdf<span class="token punctuation">.</span><span class="token function">CellFormat</span><span class="token punctuation">(</span><span class="token number">0</span><span class="token punctuation">,</span> <span class="token number">6</span><span class="token punctuation">,</span> fmt<span class="token punctuation">.</span><span class="token function">Sprintf</span><span class="token punctuation">(</span><span class="token string">"Chapter %d : %s"</span><span class="token punctuation">,</span> chapNum<span class="token punctuation">,</span> titleStr<span class="token punctuation">)</span><span class="token punctuation">,</span>
			<span class="token string">""</span><span class="token punctuation">,</span> <span class="token number">1</span><span class="token punctuation">,</span> <span class="token string">"L"</span><span class="token punctuation">,</span> <span class="token boolean">true</span><span class="token punctuation">,</span> <span class="token number">0</span><span class="token punctuation">,</span> <span class="token string">""</span><span class="token punctuation">)</span>
		<span class="token comment">// Line break</span>
		pdf<span class="token punctuation">.</span><span class="token function">Ln</span><span class="token punctuation">(</span><span class="token number">4</span><span class="token punctuation">)</span>
		y0 <span class="token operator">=</span> pdf<span class="token punctuation">.</span><span class="token function">GetY</span><span class="token punctuation">(</span><span class="token punctuation">)</span>
	<span class="token punctuation">&#125;</span>
	chapterBody <span class="token operator">:=</span> <span class="token keyword">func</span><span class="token punctuation">(</span>fileStr <span class="token builtin">string</span><span class="token punctuation">)</span> <span class="token punctuation">&#123;</span>
		<span class="token comment">// Read text file</span>
		txtStr<span class="token punctuation">,</span> err <span class="token operator">:=</span> ioutil<span class="token punctuation">.</span><span class="token function">ReadFile</span><span class="token punctuation">(</span>fileStr<span class="token punctuation">)</span>
		<span class="token keyword">if</span> err <span class="token operator">!=</span> <span class="token boolean">nil</span> <span class="token punctuation">&#123;</span>
			pdf<span class="token punctuation">.</span><span class="token function">SetError</span><span class="token punctuation">(</span>err<span class="token punctuation">)</span>
		<span class="token punctuation">&#125;</span>
		<span class="token comment">// Font</span>
		pdf<span class="token punctuation">.</span><span class="token function">SetFont</span><span class="token punctuation">(</span><span class="token string">"Times"</span><span class="token punctuation">,</span> <span class="token string">""</span><span class="token punctuation">,</span> <span class="token number">12</span><span class="token punctuation">)</span>
		<span class="token comment">// Output text in a 6 cm width column</span>
		pdf<span class="token punctuation">.</span><span class="token function">MultiCell</span><span class="token punctuation">(</span><span class="token number">60</span><span class="token punctuation">,</span> <span class="token number">5</span><span class="token punctuation">,</span> <span class="token function">string</span><span class="token punctuation">(</span>txtStr<span class="token punctuation">)</span><span class="token punctuation">,</span> <span class="token string">""</span><span class="token punctuation">,</span> <span class="token string">""</span><span class="token punctuation">,</span> <span class="token boolean">false</span><span class="token punctuation">)</span>
		pdf<span class="token punctuation">.</span><span class="token function">Ln</span><span class="token punctuation">(</span><span class="token operator">-</span><span class="token number">1</span><span class="token punctuation">)</span>
		<span class="token comment">// Mention</span>
		pdf<span class="token punctuation">.</span><span class="token function">SetFont</span><span class="token punctuation">(</span><span class="token string">""</span><span class="token punctuation">,</span> <span class="token string">"I"</span><span class="token punctuation">,</span> <span class="token number">0</span><span class="token punctuation">)</span>
		pdf<span class="token punctuation">.</span><span class="token function">Cell</span><span class="token punctuation">(</span><span class="token number">0</span><span class="token punctuation">,</span> <span class="token number">5</span><span class="token punctuation">,</span> <span class="token string">"(end of excerpt)"</span><span class="token punctuation">)</span>
		<span class="token comment">// Go back to first column</span>
		<span class="token function">setCol</span><span class="token punctuation">(</span><span class="token number">0</span><span class="token punctuation">)</span>
	<span class="token punctuation">&#125;</span>
	printChapter <span class="token operator">:=</span> <span class="token keyword">func</span><span class="token punctuation">(</span>num <span class="token builtin">int</span><span class="token punctuation">,</span> titleStr<span class="token punctuation">,</span> fileStr <span class="token builtin">string</span><span class="token punctuation">)</span> <span class="token punctuation">&#123;</span>
		<span class="token comment">// Add chapter</span>
		pdf<span class="token punctuation">.</span><span class="token function">AddPage</span><span class="token punctuation">(</span><span class="token punctuation">)</span>
		<span class="token function">chapterTitle</span><span class="token punctuation">(</span>num<span class="token punctuation">,</span> titleStr<span class="token punctuation">)</span>
		<span class="token function">chapterBody</span><span class="token punctuation">(</span>fileStr<span class="token punctuation">)</span>
	<span class="token punctuation">&#125;</span>
	pdf<span class="token punctuation">.</span><span class="token function">SetAcceptPageBreakFunc</span><span class="token punctuation">(</span><span class="token keyword">func</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token builtin">bool</span> <span class="token punctuation">&#123;</span>
		<span class="token comment">// Method accepting or not automatic page break</span>
		<span class="token keyword">if</span> crrntCol <span class="token operator">&lt;</span> <span class="token number">2</span> <span class="token punctuation">&#123;</span>
			<span class="token comment">// Go to next column</span>
			<span class="token function">setCol</span><span class="token punctuation">(</span>crrntCol <span class="token operator">+</span> <span class="token number">1</span><span class="token punctuation">)</span>
			<span class="token comment">// Set ordinate to top</span>
			pdf<span class="token punctuation">.</span><span class="token function">SetY</span><span class="token punctuation">(</span>y0<span class="token punctuation">)</span>
			<span class="token comment">// Keep on page</span>
			<span class="token keyword">return</span> <span class="token boolean">false</span>
		<span class="token punctuation">&#125;</span>
		<span class="token comment">// Go back to first column</span>
		<span class="token function">setCol</span><span class="token punctuation">(</span><span class="token number">0</span><span class="token punctuation">)</span>
		<span class="token comment">// Page break</span>
		<span class="token keyword">return</span> <span class="token boolean">true</span>
	<span class="token punctuation">&#125;</span><span class="token punctuation">)</span>
	pdf<span class="token punctuation">.</span><span class="token function">SetHeaderFunc</span><span class="token punctuation">(</span><span class="token keyword">func</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">&#123;</span>
		<span class="token comment">// Arial bold 15</span>
		pdf<span class="token punctuation">.</span><span class="token function">SetFont</span><span class="token punctuation">(</span><span class="token string">"Arial"</span><span class="token punctuation">,</span> <span class="token string">"B"</span><span class="token punctuation">,</span> <span class="token number">15</span><span class="token punctuation">)</span>
		<span class="token comment">// Calculate width of title and position</span>
		wd <span class="token operator">:=</span> pdf<span class="token punctuation">.</span><span class="token function">GetStringWidth</span><span class="token punctuation">(</span>titleStr<span class="token punctuation">)</span> <span class="token operator">+</span> <span class="token number">6</span>
		pdf<span class="token punctuation">.</span><span class="token function">SetX</span><span class="token punctuation">(</span><span class="token punctuation">(</span><span class="token number">210</span> <span class="token operator">-</span> wd<span class="token punctuation">)</span> <span class="token operator">/</span> <span class="token number">2</span><span class="token punctuation">)</span>
		<span class="token comment">// Colors of frame, background and text</span>
		pdf<span class="token punctuation">.</span><span class="token function">SetDrawColor</span><span class="token punctuation">(</span><span class="token number">0</span><span class="token punctuation">,</span> <span class="token number">80</span><span class="token punctuation">,</span> <span class="token number">180</span><span class="token punctuation">)</span>
		pdf<span class="token punctuation">.</span><span class="token function">SetFillColor</span><span class="token punctuation">(</span><span class="token number">230</span><span class="token punctuation">,</span> <span class="token number">230</span><span class="token punctuation">,</span> <span class="token number">0</span><span class="token punctuation">)</span>
		pdf<span class="token punctuation">.</span><span class="token function">SetTextColor</span><span class="token punctuation">(</span><span class="token number">220</span><span class="token punctuation">,</span> <span class="token number">50</span><span class="token punctuation">,</span> <span class="token number">50</span><span class="token punctuation">)</span>
		<span class="token comment">// Thickness of frame (1 mm)</span>
		pdf<span class="token punctuation">.</span><span class="token function">SetLineWidth</span><span class="token punctuation">(</span><span class="token number">1</span><span class="token punctuation">)</span>
		<span class="token comment">// Title</span>
		pdf<span class="token punctuation">.</span><span class="token function">CellFormat</span><span class="token punctuation">(</span>wd<span class="token punctuation">,</span> <span class="token number">9</span><span class="token punctuation">,</span> titleStr<span class="token punctuation">,</span> <span class="token string">"1"</span><span class="token punctuation">,</span> <span class="token number">1</span><span class="token punctuation">,</span> <span class="token string">"C"</span><span class="token punctuation">,</span> <span class="token boolean">true</span><span class="token punctuation">,</span> <span class="token number">0</span><span class="token punctuation">,</span> <span class="token string">""</span><span class="token punctuation">)</span>
		<span class="token comment">// Line break</span>
		pdf<span class="token punctuation">.</span><span class="token function">Ln</span><span class="token punctuation">(</span><span class="token number">10</span><span class="token punctuation">)</span>
		<span class="token comment">// Save ordinate</span>
		y0 <span class="token operator">=</span> pdf<span class="token punctuation">.</span><span class="token function">GetY</span><span class="token punctuation">(</span><span class="token punctuation">)</span>
	<span class="token punctuation">&#125;</span><span class="token punctuation">)</span>
	pdf<span class="token punctuation">.</span><span class="token function">SetFooterFunc</span><span class="token punctuation">(</span><span class="token keyword">func</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">&#123;</span>
		<span class="token comment">// Position at 1.5 cm from bottom</span>
		pdf<span class="token punctuation">.</span><span class="token function">SetY</span><span class="token punctuation">(</span><span class="token operator">-</span><span class="token number">15</span><span class="token punctuation">)</span>
		<span class="token comment">// Arial italic 8</span>
		pdf<span class="token punctuation">.</span><span class="token function">SetFont</span><span class="token punctuation">(</span><span class="token string">"Arial"</span><span class="token punctuation">,</span> <span class="token string">"I"</span><span class="token punctuation">,</span> <span class="token number">8</span><span class="token punctuation">)</span>
		<span class="token comment">// Text color in gray</span>
		pdf<span class="token punctuation">.</span><span class="token function">SetTextColor</span><span class="token punctuation">(</span><span class="token number">128</span><span class="token punctuation">,</span> <span class="token number">128</span><span class="token punctuation">,</span> <span class="token number">128</span><span class="token punctuation">)</span>
		<span class="token comment">// Page number</span>
		pdf<span class="token punctuation">.</span><span class="token function">CellFormat</span><span class="token punctuation">(</span><span class="token number">0</span><span class="token punctuation">,</span> <span class="token number">10</span><span class="token punctuation">,</span> fmt<span class="token punctuation">.</span><span class="token function">Sprintf</span><span class="token punctuation">(</span><span class="token string">"Page %d"</span><span class="token punctuation">,</span> pdf<span class="token punctuation">.</span><span class="token function">PageNo</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">,</span>
			<span class="token string">""</span><span class="token punctuation">,</span> <span class="token number">0</span><span class="token punctuation">,</span> <span class="token string">"C"</span><span class="token punctuation">,</span> <span class="token boolean">false</span><span class="token punctuation">,</span> <span class="token number">0</span><span class="token punctuation">,</span> <span class="token string">""</span><span class="token punctuation">)</span>
	<span class="token punctuation">&#125;</span><span class="token punctuation">)</span>
	<span class="token function">printChapter</span><span class="token punctuation">(</span><span class="token number">1</span><span class="token punctuation">,</span> <span class="token string">"A RUNAWAY REEF"</span><span class="token punctuation">,</span> example<span class="token punctuation">.</span><span class="token function">TextFile</span><span class="token punctuation">(</span><span class="token string">"20k_c1.txt"</span><span class="token punctuation">)</span><span class="token punctuation">)</span>
	<span class="token function">printChapter</span><span class="token punctuation">(</span><span class="token number">2</span><span class="token punctuation">,</span> <span class="token string">"THE PROS AND CONS"</span><span class="token punctuation">,</span> example<span class="token punctuation">.</span><span class="token function">TextFile</span><span class="token punctuation">(</span><span class="token string">"20k_c2.txt"</span><span class="token punctuation">)</span><span class="token punctuation">)</span>
	fileStr <span class="token operator">:=</span> example<span class="token punctuation">.</span><span class="token function">Filename</span><span class="token punctuation">(</span><span class="token string">"Fpdf_SetLeftMargin_multicolumn"</span><span class="token punctuation">)</span>
	err <span class="token operator">:=</span> pdf<span class="token punctuation">.</span><span class="token function">OutputFileAndClose</span><span class="token punctuation">(</span>fileStr<span class="token punctuation">)</span>
	example<span class="token punctuation">.</span><span class="token function">Summary</span><span class="token punctuation">(</span>err<span class="token punctuation">,</span> fileStr<span class="token punctuation">)</span>
	<span class="token comment">// Output:</span>
	<span class="token comment">// Successfully generated pdf/Fpdf_SetLeftMargin_multicolumn.pdf</span>
<span class="token punctuation">&#125;</span></code></pre>

<h2 id="演示文字换行的表格单元格"><a href="#演示文字换行的表格单元格" class="headerlink" title="演示文字换行的表格单元格"></a>演示文字换行的表格单元格</h2><pre class="language-go" data-language="go"><code class="language-go"><span class="token comment">// ExampleFpdf_SplitLines_tables demonstrates word-wrapped table cells</span>
<span class="token keyword">func</span> <span class="token function">ExampleFpdf_SplitLines_tables</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">&#123;</span>
	<span class="token keyword">const</span> <span class="token punctuation">(</span>
		colCount <span class="token operator">=</span> <span class="token number">3</span>
		colWd    <span class="token operator">=</span> <span class="token number">60.0</span>
		marginH  <span class="token operator">=</span> <span class="token number">15.0</span>
		lineHt   <span class="token operator">=</span> <span class="token number">5.5</span>
		cellGap  <span class="token operator">=</span> <span class="token number">2.0</span>
	<span class="token punctuation">)</span>
	<span class="token comment">// var colStrList [colCount]string</span>
	<span class="token keyword">type</span> cellType <span class="token keyword">struct</span> <span class="token punctuation">&#123;</span>
		str  <span class="token builtin">string</span>
		list <span class="token punctuation">[</span><span class="token punctuation">]</span><span class="token punctuation">[</span><span class="token punctuation">]</span><span class="token builtin">byte</span>
		ht   <span class="token builtin">float64</span>
	<span class="token punctuation">&#125;</span>
	<span class="token keyword">var</span> <span class="token punctuation">(</span>
		cellList <span class="token punctuation">[</span>colCount<span class="token punctuation">]</span>cellType
		cell     cellType
	<span class="token punctuation">)</span>

	pdf <span class="token operator">:=</span> gofpdf<span class="token punctuation">.</span><span class="token function">New</span><span class="token punctuation">(</span><span class="token string">"P"</span><span class="token punctuation">,</span> <span class="token string">"mm"</span><span class="token punctuation">,</span> <span class="token string">"A4"</span><span class="token punctuation">,</span> <span class="token string">""</span><span class="token punctuation">)</span> <span class="token comment">// 210 x 297</span>
	header <span class="token operator">:=</span> <span class="token punctuation">[</span>colCount<span class="token punctuation">]</span><span class="token builtin">string</span><span class="token punctuation">&#123;</span><span class="token string">"Column A"</span><span class="token punctuation">,</span> <span class="token string">"Column B"</span><span class="token punctuation">,</span> <span class="token string">"Column C"</span><span class="token punctuation">&#125;</span>
	alignList <span class="token operator">:=</span> <span class="token punctuation">[</span>colCount<span class="token punctuation">]</span><span class="token builtin">string</span><span class="token punctuation">&#123;</span><span class="token string">"L"</span><span class="token punctuation">,</span> <span class="token string">"C"</span><span class="token punctuation">,</span> <span class="token string">"R"</span><span class="token punctuation">&#125;</span>
	strList <span class="token operator">:=</span> <span class="token function">loremList</span><span class="token punctuation">(</span><span class="token punctuation">)</span>
	pdf<span class="token punctuation">.</span><span class="token function">SetMargins</span><span class="token punctuation">(</span>marginH<span class="token punctuation">,</span> <span class="token number">15</span><span class="token punctuation">,</span> marginH<span class="token punctuation">)</span>
	pdf<span class="token punctuation">.</span><span class="token function">SetFont</span><span class="token punctuation">(</span><span class="token string">"Arial"</span><span class="token punctuation">,</span> <span class="token string">""</span><span class="token punctuation">,</span> <span class="token number">14</span><span class="token punctuation">)</span>
	pdf<span class="token punctuation">.</span><span class="token function">AddPage</span><span class="token punctuation">(</span><span class="token punctuation">)</span>

	<span class="token comment">// Headers</span>
	pdf<span class="token punctuation">.</span><span class="token function">SetTextColor</span><span class="token punctuation">(</span><span class="token number">224</span><span class="token punctuation">,</span> <span class="token number">224</span><span class="token punctuation">,</span> <span class="token number">224</span><span class="token punctuation">)</span>
	pdf<span class="token punctuation">.</span><span class="token function">SetFillColor</span><span class="token punctuation">(</span><span class="token number">64</span><span class="token punctuation">,</span> <span class="token number">64</span><span class="token punctuation">,</span> <span class="token number">64</span><span class="token punctuation">)</span>
	<span class="token keyword">for</span> colJ <span class="token operator">:=</span> <span class="token number">0</span><span class="token punctuation">;</span> colJ <span class="token operator">&lt;</span> colCount<span class="token punctuation">;</span> colJ<span class="token operator">++</span> <span class="token punctuation">&#123;</span>
		pdf<span class="token punctuation">.</span><span class="token function">CellFormat</span><span class="token punctuation">(</span>colWd<span class="token punctuation">,</span> <span class="token number">10</span><span class="token punctuation">,</span> header<span class="token punctuation">[</span>colJ<span class="token punctuation">]</span><span class="token punctuation">,</span> <span class="token string">"1"</span><span class="token punctuation">,</span> <span class="token number">0</span><span class="token punctuation">,</span> <span class="token string">"CM"</span><span class="token punctuation">,</span> <span class="token boolean">true</span><span class="token punctuation">,</span> <span class="token number">0</span><span class="token punctuation">,</span> <span class="token string">""</span><span class="token punctuation">)</span>
	<span class="token punctuation">&#125;</span>
	pdf<span class="token punctuation">.</span><span class="token function">Ln</span><span class="token punctuation">(</span><span class="token operator">-</span><span class="token number">1</span><span class="token punctuation">)</span>
	pdf<span class="token punctuation">.</span><span class="token function">SetTextColor</span><span class="token punctuation">(</span><span class="token number">24</span><span class="token punctuation">,</span> <span class="token number">24</span><span class="token punctuation">,</span> <span class="token number">24</span><span class="token punctuation">)</span>
	pdf<span class="token punctuation">.</span><span class="token function">SetFillColor</span><span class="token punctuation">(</span><span class="token number">255</span><span class="token punctuation">,</span> <span class="token number">255</span><span class="token punctuation">,</span> <span class="token number">255</span><span class="token punctuation">)</span>

	<span class="token comment">// Rows</span>
	y <span class="token operator">:=</span> pdf<span class="token punctuation">.</span><span class="token function">GetY</span><span class="token punctuation">(</span><span class="token punctuation">)</span>
	count <span class="token operator">:=</span> <span class="token number">0</span>
	<span class="token keyword">for</span> rowJ <span class="token operator">:=</span> <span class="token number">0</span><span class="token punctuation">;</span> rowJ <span class="token operator">&lt;</span> <span class="token number">2</span><span class="token punctuation">;</span> rowJ<span class="token operator">++</span> <span class="token punctuation">&#123;</span>
		maxHt <span class="token operator">:=</span> lineHt
		<span class="token comment">// Cell height calculation loop</span>
		<span class="token keyword">for</span> colJ <span class="token operator">:=</span> <span class="token number">0</span><span class="token punctuation">;</span> colJ <span class="token operator">&lt;</span> colCount<span class="token punctuation">;</span> colJ<span class="token operator">++</span> <span class="token punctuation">&#123;</span>
			count<span class="token operator">++</span>
			<span class="token keyword">if</span> count <span class="token operator">></span> <span class="token function">len</span><span class="token punctuation">(</span>strList<span class="token punctuation">)</span> <span class="token punctuation">&#123;</span>
				count <span class="token operator">=</span> <span class="token number">1</span>
			<span class="token punctuation">&#125;</span>
			cell<span class="token punctuation">.</span>str <span class="token operator">=</span> strings<span class="token punctuation">.</span><span class="token function">Join</span><span class="token punctuation">(</span>strList<span class="token punctuation">[</span><span class="token number">0</span><span class="token punctuation">:</span>count<span class="token punctuation">]</span><span class="token punctuation">,</span> <span class="token string">" "</span><span class="token punctuation">)</span>
			cell<span class="token punctuation">.</span>list <span class="token operator">=</span> pdf<span class="token punctuation">.</span><span class="token function">SplitLines</span><span class="token punctuation">(</span><span class="token punctuation">[</span><span class="token punctuation">]</span><span class="token function">byte</span><span class="token punctuation">(</span>cell<span class="token punctuation">.</span>str<span class="token punctuation">)</span><span class="token punctuation">,</span> colWd<span class="token operator">-</span>cellGap<span class="token operator">-</span>cellGap<span class="token punctuation">)</span>
			cell<span class="token punctuation">.</span>ht <span class="token operator">=</span> <span class="token function">float64</span><span class="token punctuation">(</span><span class="token function">len</span><span class="token punctuation">(</span>cell<span class="token punctuation">.</span>list<span class="token punctuation">)</span><span class="token punctuation">)</span> <span class="token operator">*</span> lineHt
			<span class="token keyword">if</span> cell<span class="token punctuation">.</span>ht <span class="token operator">></span> maxHt <span class="token punctuation">&#123;</span>
				maxHt <span class="token operator">=</span> cell<span class="token punctuation">.</span>ht
			<span class="token punctuation">&#125;</span>
			cellList<span class="token punctuation">[</span>colJ<span class="token punctuation">]</span> <span class="token operator">=</span> cell
		<span class="token punctuation">&#125;</span>
		<span class="token comment">// Cell render loop</span>
		x <span class="token operator">:=</span> marginH
		<span class="token keyword">for</span> colJ <span class="token operator">:=</span> <span class="token number">0</span><span class="token punctuation">;</span> colJ <span class="token operator">&lt;</span> colCount<span class="token punctuation">;</span> colJ<span class="token operator">++</span> <span class="token punctuation">&#123;</span>
			pdf<span class="token punctuation">.</span><span class="token function">Rect</span><span class="token punctuation">(</span>x<span class="token punctuation">,</span> y<span class="token punctuation">,</span> colWd<span class="token punctuation">,</span> maxHt<span class="token operator">+</span>cellGap<span class="token operator">+</span>cellGap<span class="token punctuation">,</span> <span class="token string">"D"</span><span class="token punctuation">)</span>
			cell <span class="token operator">=</span> cellList<span class="token punctuation">[</span>colJ<span class="token punctuation">]</span>
			cellY <span class="token operator">:=</span> y <span class="token operator">+</span> cellGap <span class="token operator">+</span> <span class="token punctuation">(</span>maxHt<span class="token operator">-</span>cell<span class="token punctuation">.</span>ht<span class="token punctuation">)</span><span class="token operator">/</span><span class="token number">2</span>
			<span class="token keyword">for</span> splitJ <span class="token operator">:=</span> <span class="token number">0</span><span class="token punctuation">;</span> splitJ <span class="token operator">&lt;</span> <span class="token function">len</span><span class="token punctuation">(</span>cell<span class="token punctuation">.</span>list<span class="token punctuation">)</span><span class="token punctuation">;</span> splitJ<span class="token operator">++</span> <span class="token punctuation">&#123;</span>
				pdf<span class="token punctuation">.</span><span class="token function">SetXY</span><span class="token punctuation">(</span>x<span class="token operator">+</span>cellGap<span class="token punctuation">,</span> cellY<span class="token punctuation">)</span>
				pdf<span class="token punctuation">.</span><span class="token function">CellFormat</span><span class="token punctuation">(</span>colWd<span class="token operator">-</span>cellGap<span class="token operator">-</span>cellGap<span class="token punctuation">,</span> lineHt<span class="token punctuation">,</span> <span class="token function">string</span><span class="token punctuation">(</span>cell<span class="token punctuation">.</span>list<span class="token punctuation">[</span>splitJ<span class="token punctuation">]</span><span class="token punctuation">)</span><span class="token punctuation">,</span> <span class="token string">""</span><span class="token punctuation">,</span> <span class="token number">0</span><span class="token punctuation">,</span>
					alignList<span class="token punctuation">[</span>colJ<span class="token punctuation">]</span><span class="token punctuation">,</span> <span class="token boolean">false</span><span class="token punctuation">,</span> <span class="token number">0</span><span class="token punctuation">,</span> <span class="token string">""</span><span class="token punctuation">)</span>
				cellY <span class="token operator">+=</span> lineHt
			<span class="token punctuation">&#125;</span>
			x <span class="token operator">+=</span> colWd
		<span class="token punctuation">&#125;</span>
		y <span class="token operator">+=</span> maxHt <span class="token operator">+</span> cellGap <span class="token operator">+</span> cellGap
	<span class="token punctuation">&#125;</span>

	fileStr <span class="token operator">:=</span> example<span class="token punctuation">.</span><span class="token function">Filename</span><span class="token punctuation">(</span><span class="token string">"Fpdf_SplitLines_tables"</span><span class="token punctuation">)</span>
	err <span class="token operator">:=</span> pdf<span class="token punctuation">.</span><span class="token function">OutputFileAndClose</span><span class="token punctuation">(</span>fileStr<span class="token punctuation">)</span>
	example<span class="token punctuation">.</span><span class="token function">Summary</span><span class="token punctuation">(</span>err<span class="token punctuation">,</span> fileStr<span class="token punctuation">)</span>
	<span class="token comment">// Output:</span>
	<span class="token comment">// Successfully generated pdf/Fpdf_SplitLines_tables.pdf</span>
<span class="token punctuation">&#125;</span></code></pre>

<h2 id="演示各种表格样式"><a href="#演示各种表格样式" class="headerlink" title="演示各种表格样式"></a>演示各种表格样式</h2><pre class="language-go" data-language="go"><code class="language-go"><span class="token comment">// ExampleFpdf_CellFormat_tables demonstrates various table styles.</span>
<span class="token keyword">func</span> <span class="token function">ExampleFpdf_CellFormat_tables</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">&#123;</span>
	pdf <span class="token operator">:=</span> gofpdf<span class="token punctuation">.</span><span class="token function">New</span><span class="token punctuation">(</span><span class="token string">"P"</span><span class="token punctuation">,</span> <span class="token string">"mm"</span><span class="token punctuation">,</span> <span class="token string">"A4"</span><span class="token punctuation">,</span> <span class="token string">""</span><span class="token punctuation">)</span>
	<span class="token keyword">type</span> countryType <span class="token keyword">struct</span> <span class="token punctuation">&#123;</span>
		nameStr<span class="token punctuation">,</span> capitalStr<span class="token punctuation">,</span> areaStr<span class="token punctuation">,</span> popStr <span class="token builtin">string</span>
	<span class="token punctuation">&#125;</span>
	countryList <span class="token operator">:=</span> <span class="token function">make</span><span class="token punctuation">(</span><span class="token punctuation">[</span><span class="token punctuation">]</span>countryType<span class="token punctuation">,</span> <span class="token number">0</span><span class="token punctuation">,</span> <span class="token number">8</span><span class="token punctuation">)</span>
	header <span class="token operator">:=</span> <span class="token punctuation">[</span><span class="token punctuation">]</span><span class="token builtin">string</span><span class="token punctuation">&#123;</span><span class="token string">"Country"</span><span class="token punctuation">,</span> <span class="token string">"Capital"</span><span class="token punctuation">,</span> <span class="token string">"Area (sq km)"</span><span class="token punctuation">,</span> <span class="token string">"Pop. (thousands)"</span><span class="token punctuation">&#125;</span>
	loadData <span class="token operator">:=</span> <span class="token keyword">func</span><span class="token punctuation">(</span>fileStr <span class="token builtin">string</span><span class="token punctuation">)</span> <span class="token punctuation">&#123;</span>
		fl<span class="token punctuation">,</span> err <span class="token operator">:=</span> os<span class="token punctuation">.</span><span class="token function">Open</span><span class="token punctuation">(</span>fileStr<span class="token punctuation">)</span>
		<span class="token keyword">if</span> err <span class="token operator">==</span> <span class="token boolean">nil</span> <span class="token punctuation">&#123;</span>
			scanner <span class="token operator">:=</span> bufio<span class="token punctuation">.</span><span class="token function">NewScanner</span><span class="token punctuation">(</span>fl<span class="token punctuation">)</span>
			<span class="token keyword">var</span> c countryType
			<span class="token keyword">for</span> scanner<span class="token punctuation">.</span><span class="token function">Scan</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">&#123;</span>
				<span class="token comment">// Austria;Vienna;83859;8075</span>
				lineStr <span class="token operator">:=</span> scanner<span class="token punctuation">.</span><span class="token function">Text</span><span class="token punctuation">(</span><span class="token punctuation">)</span>
				list <span class="token operator">:=</span> strings<span class="token punctuation">.</span><span class="token function">Split</span><span class="token punctuation">(</span>lineStr<span class="token punctuation">,</span> <span class="token string">";"</span><span class="token punctuation">)</span>
				<span class="token keyword">if</span> <span class="token function">len</span><span class="token punctuation">(</span>list<span class="token punctuation">)</span> <span class="token operator">==</span> <span class="token number">4</span> <span class="token punctuation">&#123;</span>
					c<span class="token punctuation">.</span>nameStr <span class="token operator">=</span> list<span class="token punctuation">[</span><span class="token number">0</span><span class="token punctuation">]</span>
					c<span class="token punctuation">.</span>capitalStr <span class="token operator">=</span> list<span class="token punctuation">[</span><span class="token number">1</span><span class="token punctuation">]</span>
					c<span class="token punctuation">.</span>areaStr <span class="token operator">=</span> list<span class="token punctuation">[</span><span class="token number">2</span><span class="token punctuation">]</span>
					c<span class="token punctuation">.</span>popStr <span class="token operator">=</span> list<span class="token punctuation">[</span><span class="token number">3</span><span class="token punctuation">]</span>
					countryList <span class="token operator">=</span> <span class="token function">append</span><span class="token punctuation">(</span>countryList<span class="token punctuation">,</span> c<span class="token punctuation">)</span>
				<span class="token punctuation">&#125;</span> <span class="token keyword">else</span> <span class="token punctuation">&#123;</span>
					err <span class="token operator">=</span> fmt<span class="token punctuation">.</span><span class="token function">Errorf</span><span class="token punctuation">(</span><span class="token string">"error tokenizing %s"</span><span class="token punctuation">,</span> lineStr<span class="token punctuation">)</span>
				<span class="token punctuation">&#125;</span>
			<span class="token punctuation">&#125;</span>
			fl<span class="token punctuation">.</span><span class="token function">Close</span><span class="token punctuation">(</span><span class="token punctuation">)</span>
			<span class="token keyword">if</span> <span class="token function">len</span><span class="token punctuation">(</span>countryList<span class="token punctuation">)</span> <span class="token operator">==</span> <span class="token number">0</span> <span class="token punctuation">&#123;</span>
				err <span class="token operator">=</span> fmt<span class="token punctuation">.</span><span class="token function">Errorf</span><span class="token punctuation">(</span><span class="token string">"error loading data from %s"</span><span class="token punctuation">,</span> fileStr<span class="token punctuation">)</span>
			<span class="token punctuation">&#125;</span>
		<span class="token punctuation">&#125;</span>
		<span class="token keyword">if</span> err <span class="token operator">!=</span> <span class="token boolean">nil</span> <span class="token punctuation">&#123;</span>
			pdf<span class="token punctuation">.</span><span class="token function">SetError</span><span class="token punctuation">(</span>err<span class="token punctuation">)</span>
		<span class="token punctuation">&#125;</span>
	<span class="token punctuation">&#125;</span>
	<span class="token comment">// Simple table</span>
	basicTable <span class="token operator">:=</span> <span class="token keyword">func</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">&#123;</span>
		left <span class="token operator">:=</span> <span class="token punctuation">(</span><span class="token number">210.0</span> <span class="token operator">-</span> <span class="token number">4</span><span class="token operator">*</span><span class="token number">40</span><span class="token punctuation">)</span> <span class="token operator">/</span> <span class="token number">2</span>
		pdf<span class="token punctuation">.</span><span class="token function">SetX</span><span class="token punctuation">(</span>left<span class="token punctuation">)</span>
		<span class="token keyword">for</span> <span class="token boolean">_</span><span class="token punctuation">,</span> str <span class="token operator">:=</span> <span class="token keyword">range</span> header <span class="token punctuation">&#123;</span>
			pdf<span class="token punctuation">.</span><span class="token function">CellFormat</span><span class="token punctuation">(</span><span class="token number">40</span><span class="token punctuation">,</span> <span class="token number">7</span><span class="token punctuation">,</span> str<span class="token punctuation">,</span> <span class="token string">"1"</span><span class="token punctuation">,</span> <span class="token number">0</span><span class="token punctuation">,</span> <span class="token string">""</span><span class="token punctuation">,</span> <span class="token boolean">false</span><span class="token punctuation">,</span> <span class="token number">0</span><span class="token punctuation">,</span> <span class="token string">""</span><span class="token punctuation">)</span>
		<span class="token punctuation">&#125;</span>
		pdf<span class="token punctuation">.</span><span class="token function">Ln</span><span class="token punctuation">(</span><span class="token operator">-</span><span class="token number">1</span><span class="token punctuation">)</span>
		<span class="token keyword">for</span> <span class="token boolean">_</span><span class="token punctuation">,</span> c <span class="token operator">:=</span> <span class="token keyword">range</span> countryList <span class="token punctuation">&#123;</span>
			pdf<span class="token punctuation">.</span><span class="token function">SetX</span><span class="token punctuation">(</span>left<span class="token punctuation">)</span>
			pdf<span class="token punctuation">.</span><span class="token function">CellFormat</span><span class="token punctuation">(</span><span class="token number">40</span><span class="token punctuation">,</span> <span class="token number">6</span><span class="token punctuation">,</span> c<span class="token punctuation">.</span>nameStr<span class="token punctuation">,</span> <span class="token string">"1"</span><span class="token punctuation">,</span> <span class="token number">0</span><span class="token punctuation">,</span> <span class="token string">""</span><span class="token punctuation">,</span> <span class="token boolean">false</span><span class="token punctuation">,</span> <span class="token number">0</span><span class="token punctuation">,</span> <span class="token string">""</span><span class="token punctuation">)</span>
			pdf<span class="token punctuation">.</span><span class="token function">CellFormat</span><span class="token punctuation">(</span><span class="token number">40</span><span class="token punctuation">,</span> <span class="token number">6</span><span class="token punctuation">,</span> c<span class="token punctuation">.</span>capitalStr<span class="token punctuation">,</span> <span class="token string">"1"</span><span class="token punctuation">,</span> <span class="token number">0</span><span class="token punctuation">,</span> <span class="token string">""</span><span class="token punctuation">,</span> <span class="token boolean">false</span><span class="token punctuation">,</span> <span class="token number">0</span><span class="token punctuation">,</span> <span class="token string">""</span><span class="token punctuation">)</span>
			pdf<span class="token punctuation">.</span><span class="token function">CellFormat</span><span class="token punctuation">(</span><span class="token number">40</span><span class="token punctuation">,</span> <span class="token number">6</span><span class="token punctuation">,</span> c<span class="token punctuation">.</span>areaStr<span class="token punctuation">,</span> <span class="token string">"1"</span><span class="token punctuation">,</span> <span class="token number">0</span><span class="token punctuation">,</span> <span class="token string">""</span><span class="token punctuation">,</span> <span class="token boolean">false</span><span class="token punctuation">,</span> <span class="token number">0</span><span class="token punctuation">,</span> <span class="token string">""</span><span class="token punctuation">)</span>
			pdf<span class="token punctuation">.</span><span class="token function">CellFormat</span><span class="token punctuation">(</span><span class="token number">40</span><span class="token punctuation">,</span> <span class="token number">6</span><span class="token punctuation">,</span> c<span class="token punctuation">.</span>popStr<span class="token punctuation">,</span> <span class="token string">"1"</span><span class="token punctuation">,</span> <span class="token number">0</span><span class="token punctuation">,</span> <span class="token string">""</span><span class="token punctuation">,</span> <span class="token boolean">false</span><span class="token punctuation">,</span> <span class="token number">0</span><span class="token punctuation">,</span> <span class="token string">""</span><span class="token punctuation">)</span>
			pdf<span class="token punctuation">.</span><span class="token function">Ln</span><span class="token punctuation">(</span><span class="token operator">-</span><span class="token number">1</span><span class="token punctuation">)</span>
		<span class="token punctuation">&#125;</span>
	<span class="token punctuation">&#125;</span>
	<span class="token comment">// Better table</span>
	improvedTable <span class="token operator">:=</span> <span class="token keyword">func</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">&#123;</span>
		<span class="token comment">// Column widths</span>
		w <span class="token operator">:=</span> <span class="token punctuation">[</span><span class="token punctuation">]</span><span class="token builtin">float64</span><span class="token punctuation">&#123;</span><span class="token number">40.0</span><span class="token punctuation">,</span> <span class="token number">35.0</span><span class="token punctuation">,</span> <span class="token number">40.0</span><span class="token punctuation">,</span> <span class="token number">45.0</span><span class="token punctuation">&#125;</span>
		wSum <span class="token operator">:=</span> <span class="token number">0.0</span>
		<span class="token keyword">for</span> <span class="token boolean">_</span><span class="token punctuation">,</span> v <span class="token operator">:=</span> <span class="token keyword">range</span> w <span class="token punctuation">&#123;</span>
			wSum <span class="token operator">+=</span> v
		<span class="token punctuation">&#125;</span>
		left <span class="token operator">:=</span> <span class="token punctuation">(</span><span class="token number">210</span> <span class="token operator">-</span> wSum<span class="token punctuation">)</span> <span class="token operator">/</span> <span class="token number">2</span>
		<span class="token comment">// 	Header</span>
		pdf<span class="token punctuation">.</span><span class="token function">SetX</span><span class="token punctuation">(</span>left<span class="token punctuation">)</span>
		<span class="token keyword">for</span> j<span class="token punctuation">,</span> str <span class="token operator">:=</span> <span class="token keyword">range</span> header <span class="token punctuation">&#123;</span>
			pdf<span class="token punctuation">.</span><span class="token function">CellFormat</span><span class="token punctuation">(</span>w<span class="token punctuation">[</span>j<span class="token punctuation">]</span><span class="token punctuation">,</span> <span class="token number">7</span><span class="token punctuation">,</span> str<span class="token punctuation">,</span> <span class="token string">"1"</span><span class="token punctuation">,</span> <span class="token number">0</span><span class="token punctuation">,</span> <span class="token string">"C"</span><span class="token punctuation">,</span> <span class="token boolean">false</span><span class="token punctuation">,</span> <span class="token number">0</span><span class="token punctuation">,</span> <span class="token string">""</span><span class="token punctuation">)</span>
		<span class="token punctuation">&#125;</span>
		pdf<span class="token punctuation">.</span><span class="token function">Ln</span><span class="token punctuation">(</span><span class="token operator">-</span><span class="token number">1</span><span class="token punctuation">)</span>
		<span class="token comment">// Data</span>
		<span class="token keyword">for</span> <span class="token boolean">_</span><span class="token punctuation">,</span> c <span class="token operator">:=</span> <span class="token keyword">range</span> countryList <span class="token punctuation">&#123;</span>
			pdf<span class="token punctuation">.</span><span class="token function">SetX</span><span class="token punctuation">(</span>left<span class="token punctuation">)</span>
			pdf<span class="token punctuation">.</span><span class="token function">CellFormat</span><span class="token punctuation">(</span>w<span class="token punctuation">[</span><span class="token number">0</span><span class="token punctuation">]</span><span class="token punctuation">,</span> <span class="token number">6</span><span class="token punctuation">,</span> c<span class="token punctuation">.</span>nameStr<span class="token punctuation">,</span> <span class="token string">"LR"</span><span class="token punctuation">,</span> <span class="token number">0</span><span class="token punctuation">,</span> <span class="token string">""</span><span class="token punctuation">,</span> <span class="token boolean">false</span><span class="token punctuation">,</span> <span class="token number">0</span><span class="token punctuation">,</span> <span class="token string">""</span><span class="token punctuation">)</span>
			pdf<span class="token punctuation">.</span><span class="token function">CellFormat</span><span class="token punctuation">(</span>w<span class="token punctuation">[</span><span class="token number">1</span><span class="token punctuation">]</span><span class="token punctuation">,</span> <span class="token number">6</span><span class="token punctuation">,</span> c<span class="token punctuation">.</span>capitalStr<span class="token punctuation">,</span> <span class="token string">"LR"</span><span class="token punctuation">,</span> <span class="token number">0</span><span class="token punctuation">,</span> <span class="token string">""</span><span class="token punctuation">,</span> <span class="token boolean">false</span><span class="token punctuation">,</span> <span class="token number">0</span><span class="token punctuation">,</span> <span class="token string">""</span><span class="token punctuation">)</span>
			pdf<span class="token punctuation">.</span><span class="token function">CellFormat</span><span class="token punctuation">(</span>w<span class="token punctuation">[</span><span class="token number">2</span><span class="token punctuation">]</span><span class="token punctuation">,</span> <span class="token number">6</span><span class="token punctuation">,</span> <span class="token function">strDelimit</span><span class="token punctuation">(</span>c<span class="token punctuation">.</span>areaStr<span class="token punctuation">,</span> <span class="token string">","</span><span class="token punctuation">,</span> <span class="token number">3</span><span class="token punctuation">)</span><span class="token punctuation">,</span>
				<span class="token string">"LR"</span><span class="token punctuation">,</span> <span class="token number">0</span><span class="token punctuation">,</span> <span class="token string">"R"</span><span class="token punctuation">,</span> <span class="token boolean">false</span><span class="token punctuation">,</span> <span class="token number">0</span><span class="token punctuation">,</span> <span class="token string">""</span><span class="token punctuation">)</span>
			pdf<span class="token punctuation">.</span><span class="token function">CellFormat</span><span class="token punctuation">(</span>w<span class="token punctuation">[</span><span class="token number">3</span><span class="token punctuation">]</span><span class="token punctuation">,</span> <span class="token number">6</span><span class="token punctuation">,</span> <span class="token function">strDelimit</span><span class="token punctuation">(</span>c<span class="token punctuation">.</span>popStr<span class="token punctuation">,</span> <span class="token string">","</span><span class="token punctuation">,</span> <span class="token number">3</span><span class="token punctuation">)</span><span class="token punctuation">,</span>
				<span class="token string">"LR"</span><span class="token punctuation">,</span> <span class="token number">0</span><span class="token punctuation">,</span> <span class="token string">"R"</span><span class="token punctuation">,</span> <span class="token boolean">false</span><span class="token punctuation">,</span> <span class="token number">0</span><span class="token punctuation">,</span> <span class="token string">""</span><span class="token punctuation">)</span>
			pdf<span class="token punctuation">.</span><span class="token function">Ln</span><span class="token punctuation">(</span><span class="token operator">-</span><span class="token number">1</span><span class="token punctuation">)</span>
		<span class="token punctuation">&#125;</span>
		pdf<span class="token punctuation">.</span><span class="token function">SetX</span><span class="token punctuation">(</span>left<span class="token punctuation">)</span>
		pdf<span class="token punctuation">.</span><span class="token function">CellFormat</span><span class="token punctuation">(</span>wSum<span class="token punctuation">,</span> <span class="token number">0</span><span class="token punctuation">,</span> <span class="token string">""</span><span class="token punctuation">,</span> <span class="token string">"T"</span><span class="token punctuation">,</span> <span class="token number">0</span><span class="token punctuation">,</span> <span class="token string">""</span><span class="token punctuation">,</span> <span class="token boolean">false</span><span class="token punctuation">,</span> <span class="token number">0</span><span class="token punctuation">,</span> <span class="token string">""</span><span class="token punctuation">)</span>
	<span class="token punctuation">&#125;</span>
	<span class="token comment">// Colored table</span>
	fancyTable <span class="token operator">:=</span> <span class="token keyword">func</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">&#123;</span>
		<span class="token comment">// Colors, line width and bold font</span>
		pdf<span class="token punctuation">.</span><span class="token function">SetFillColor</span><span class="token punctuation">(</span><span class="token number">255</span><span class="token punctuation">,</span> <span class="token number">0</span><span class="token punctuation">,</span> <span class="token number">0</span><span class="token punctuation">)</span>
		pdf<span class="token punctuation">.</span><span class="token function">SetTextColor</span><span class="token punctuation">(</span><span class="token number">255</span><span class="token punctuation">,</span> <span class="token number">255</span><span class="token punctuation">,</span> <span class="token number">255</span><span class="token punctuation">)</span>
		pdf<span class="token punctuation">.</span><span class="token function">SetDrawColor</span><span class="token punctuation">(</span><span class="token number">128</span><span class="token punctuation">,</span> <span class="token number">0</span><span class="token punctuation">,</span> <span class="token number">0</span><span class="token punctuation">)</span>
		pdf<span class="token punctuation">.</span><span class="token function">SetLineWidth</span><span class="token punctuation">(</span><span class="token number">.3</span><span class="token punctuation">)</span>
		pdf<span class="token punctuation">.</span><span class="token function">SetFont</span><span class="token punctuation">(</span><span class="token string">""</span><span class="token punctuation">,</span> <span class="token string">"B"</span><span class="token punctuation">,</span> <span class="token number">0</span><span class="token punctuation">)</span>
		<span class="token comment">// 	Header</span>
		w <span class="token operator">:=</span> <span class="token punctuation">[</span><span class="token punctuation">]</span><span class="token builtin">float64</span><span class="token punctuation">&#123;</span><span class="token number">40</span><span class="token punctuation">,</span> <span class="token number">35</span><span class="token punctuation">,</span> <span class="token number">40</span><span class="token punctuation">,</span> <span class="token number">45</span><span class="token punctuation">&#125;</span>
		wSum <span class="token operator">:=</span> <span class="token number">0.0</span>
		<span class="token keyword">for</span> <span class="token boolean">_</span><span class="token punctuation">,</span> v <span class="token operator">:=</span> <span class="token keyword">range</span> w <span class="token punctuation">&#123;</span>
			wSum <span class="token operator">+=</span> v
		<span class="token punctuation">&#125;</span>
		left <span class="token operator">:=</span> <span class="token punctuation">(</span><span class="token number">210</span> <span class="token operator">-</span> wSum<span class="token punctuation">)</span> <span class="token operator">/</span> <span class="token number">2</span>
		pdf<span class="token punctuation">.</span><span class="token function">SetX</span><span class="token punctuation">(</span>left<span class="token punctuation">)</span>
		<span class="token keyword">for</span> j<span class="token punctuation">,</span> str <span class="token operator">:=</span> <span class="token keyword">range</span> header <span class="token punctuation">&#123;</span>
			pdf<span class="token punctuation">.</span><span class="token function">CellFormat</span><span class="token punctuation">(</span>w<span class="token punctuation">[</span>j<span class="token punctuation">]</span><span class="token punctuation">,</span> <span class="token number">7</span><span class="token punctuation">,</span> str<span class="token punctuation">,</span> <span class="token string">"1"</span><span class="token punctuation">,</span> <span class="token number">0</span><span class="token punctuation">,</span> <span class="token string">"C"</span><span class="token punctuation">,</span> <span class="token boolean">true</span><span class="token punctuation">,</span> <span class="token number">0</span><span class="token punctuation">,</span> <span class="token string">""</span><span class="token punctuation">)</span>
		<span class="token punctuation">&#125;</span>
		pdf<span class="token punctuation">.</span><span class="token function">Ln</span><span class="token punctuation">(</span><span class="token operator">-</span><span class="token number">1</span><span class="token punctuation">)</span>
		<span class="token comment">// Color and font restoration</span>
		pdf<span class="token punctuation">.</span><span class="token function">SetFillColor</span><span class="token punctuation">(</span><span class="token number">224</span><span class="token punctuation">,</span> <span class="token number">235</span><span class="token punctuation">,</span> <span class="token number">255</span><span class="token punctuation">)</span>
		pdf<span class="token punctuation">.</span><span class="token function">SetTextColor</span><span class="token punctuation">(</span><span class="token number">0</span><span class="token punctuation">,</span> <span class="token number">0</span><span class="token punctuation">,</span> <span class="token number">0</span><span class="token punctuation">)</span>
		pdf<span class="token punctuation">.</span><span class="token function">SetFont</span><span class="token punctuation">(</span><span class="token string">""</span><span class="token punctuation">,</span> <span class="token string">""</span><span class="token punctuation">,</span> <span class="token number">0</span><span class="token punctuation">)</span>
		<span class="token comment">// 	Data</span>
		fill <span class="token operator">:=</span> <span class="token boolean">false</span>
		<span class="token keyword">for</span> <span class="token boolean">_</span><span class="token punctuation">,</span> c <span class="token operator">:=</span> <span class="token keyword">range</span> countryList <span class="token punctuation">&#123;</span>
			pdf<span class="token punctuation">.</span><span class="token function">SetX</span><span class="token punctuation">(</span>left<span class="token punctuation">)</span>
			pdf<span class="token punctuation">.</span><span class="token function">CellFormat</span><span class="token punctuation">(</span>w<span class="token punctuation">[</span><span class="token number">0</span><span class="token punctuation">]</span><span class="token punctuation">,</span> <span class="token number">6</span><span class="token punctuation">,</span> c<span class="token punctuation">.</span>nameStr<span class="token punctuation">,</span> <span class="token string">"LR"</span><span class="token punctuation">,</span> <span class="token number">0</span><span class="token punctuation">,</span> <span class="token string">""</span><span class="token punctuation">,</span> fill<span class="token punctuation">,</span> <span class="token number">0</span><span class="token punctuation">,</span> <span class="token string">""</span><span class="token punctuation">)</span>
			pdf<span class="token punctuation">.</span><span class="token function">CellFormat</span><span class="token punctuation">(</span>w<span class="token punctuation">[</span><span class="token number">1</span><span class="token punctuation">]</span><span class="token punctuation">,</span> <span class="token number">6</span><span class="token punctuation">,</span> c<span class="token punctuation">.</span>capitalStr<span class="token punctuation">,</span> <span class="token string">"LR"</span><span class="token punctuation">,</span> <span class="token number">0</span><span class="token punctuation">,</span> <span class="token string">""</span><span class="token punctuation">,</span> fill<span class="token punctuation">,</span> <span class="token number">0</span><span class="token punctuation">,</span> <span class="token string">""</span><span class="token punctuation">)</span>
			pdf<span class="token punctuation">.</span><span class="token function">CellFormat</span><span class="token punctuation">(</span>w<span class="token punctuation">[</span><span class="token number">2</span><span class="token punctuation">]</span><span class="token punctuation">,</span> <span class="token number">6</span><span class="token punctuation">,</span> <span class="token function">strDelimit</span><span class="token punctuation">(</span>c<span class="token punctuation">.</span>areaStr<span class="token punctuation">,</span> <span class="token string">","</span><span class="token punctuation">,</span> <span class="token number">3</span><span class="token punctuation">)</span><span class="token punctuation">,</span>
				<span class="token string">"LR"</span><span class="token punctuation">,</span> <span class="token number">0</span><span class="token punctuation">,</span> <span class="token string">"R"</span><span class="token punctuation">,</span> fill<span class="token punctuation">,</span> <span class="token number">0</span><span class="token punctuation">,</span> <span class="token string">""</span><span class="token punctuation">)</span>
			pdf<span class="token punctuation">.</span><span class="token function">CellFormat</span><span class="token punctuation">(</span>w<span class="token punctuation">[</span><span class="token number">3</span><span class="token punctuation">]</span><span class="token punctuation">,</span> <span class="token number">6</span><span class="token punctuation">,</span> <span class="token function">strDelimit</span><span class="token punctuation">(</span>c<span class="token punctuation">.</span>popStr<span class="token punctuation">,</span> <span class="token string">","</span><span class="token punctuation">,</span> <span class="token number">3</span><span class="token punctuation">)</span><span class="token punctuation">,</span>
				<span class="token string">"LR"</span><span class="token punctuation">,</span> <span class="token number">0</span><span class="token punctuation">,</span> <span class="token string">"R"</span><span class="token punctuation">,</span> fill<span class="token punctuation">,</span> <span class="token number">0</span><span class="token punctuation">,</span> <span class="token string">""</span><span class="token punctuation">)</span>
			pdf<span class="token punctuation">.</span><span class="token function">Ln</span><span class="token punctuation">(</span><span class="token operator">-</span><span class="token number">1</span><span class="token punctuation">)</span>
			fill <span class="token operator">=</span> <span class="token operator">!</span>fill
		<span class="token punctuation">&#125;</span>
		pdf<span class="token punctuation">.</span><span class="token function">SetX</span><span class="token punctuation">(</span>left<span class="token punctuation">)</span>
		pdf<span class="token punctuation">.</span><span class="token function">CellFormat</span><span class="token punctuation">(</span>wSum<span class="token punctuation">,</span> <span class="token number">0</span><span class="token punctuation">,</span> <span class="token string">""</span><span class="token punctuation">,</span> <span class="token string">"T"</span><span class="token punctuation">,</span> <span class="token number">0</span><span class="token punctuation">,</span> <span class="token string">""</span><span class="token punctuation">,</span> <span class="token boolean">false</span><span class="token punctuation">,</span> <span class="token number">0</span><span class="token punctuation">,</span> <span class="token string">""</span><span class="token punctuation">)</span>
	<span class="token punctuation">&#125;</span>
	<span class="token function">loadData</span><span class="token punctuation">(</span>example<span class="token punctuation">.</span><span class="token function">TextFile</span><span class="token punctuation">(</span><span class="token string">"countries.txt"</span><span class="token punctuation">)</span><span class="token punctuation">)</span>
	pdf<span class="token punctuation">.</span><span class="token function">SetFont</span><span class="token punctuation">(</span><span class="token string">"Arial"</span><span class="token punctuation">,</span> <span class="token string">""</span><span class="token punctuation">,</span> <span class="token number">14</span><span class="token punctuation">)</span>
	pdf<span class="token punctuation">.</span><span class="token function">AddPage</span><span class="token punctuation">(</span><span class="token punctuation">)</span>
	<span class="token function">basicTable</span><span class="token punctuation">(</span><span class="token punctuation">)</span>
	pdf<span class="token punctuation">.</span><span class="token function">AddPage</span><span class="token punctuation">(</span><span class="token punctuation">)</span>
	<span class="token function">improvedTable</span><span class="token punctuation">(</span><span class="token punctuation">)</span>
	pdf<span class="token punctuation">.</span><span class="token function">AddPage</span><span class="token punctuation">(</span><span class="token punctuation">)</span>
	<span class="token function">fancyTable</span><span class="token punctuation">(</span><span class="token punctuation">)</span>
	fileStr <span class="token operator">:=</span> example<span class="token punctuation">.</span><span class="token function">Filename</span><span class="token punctuation">(</span><span class="token string">"Fpdf_CellFormat_tables"</span><span class="token punctuation">)</span>
	err <span class="token operator">:=</span> pdf<span class="token punctuation">.</span><span class="token function">OutputFileAndClose</span><span class="token punctuation">(</span>fileStr<span class="token punctuation">)</span>
	example<span class="token punctuation">.</span><span class="token function">Summary</span><span class="token punctuation">(</span>err<span class="token punctuation">,</span> fileStr<span class="token punctuation">)</span>
	<span class="token comment">// Output:</span>
	<span class="token comment">// Successfully generated pdf/Fpdf_CellFormat_tables.pdf</span>
<span class="token punctuation">&#125;</span></code></pre>

<h2 id="演示带有和不带基本-HTML-的内部和外部链接"><a href="#演示带有和不带基本-HTML-的内部和外部链接" class="headerlink" title="演示带有和不带基本 HTML 的内部和外部链接"></a>演示带有和不带基本 HTML 的内部和外部链接</h2><pre class="language-go" data-language="go"><code class="language-go"><span class="token comment">// ExampleFpdf_HTMLBasicNew demonstrates internal and external links with and without basic</span>
<span class="token comment">// HTML.</span>
<span class="token keyword">func</span> <span class="token function">ExampleFpdf_HTMLBasicNew</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">&#123;</span>
	pdf <span class="token operator">:=</span> gofpdf<span class="token punctuation">.</span><span class="token function">New</span><span class="token punctuation">(</span><span class="token string">"P"</span><span class="token punctuation">,</span> <span class="token string">"mm"</span><span class="token punctuation">,</span> <span class="token string">"A4"</span><span class="token punctuation">,</span> <span class="token string">""</span><span class="token punctuation">)</span>
	<span class="token comment">// First page: manual local link</span>
	pdf<span class="token punctuation">.</span><span class="token function">AddPage</span><span class="token punctuation">(</span><span class="token punctuation">)</span>
	pdf<span class="token punctuation">.</span><span class="token function">SetFont</span><span class="token punctuation">(</span><span class="token string">"Helvetica"</span><span class="token punctuation">,</span> <span class="token string">""</span><span class="token punctuation">,</span> <span class="token number">20</span><span class="token punctuation">)</span>
	<span class="token boolean">_</span><span class="token punctuation">,</span> lineHt <span class="token operator">:=</span> pdf<span class="token punctuation">.</span><span class="token function">GetFontSize</span><span class="token punctuation">(</span><span class="token punctuation">)</span>
	pdf<span class="token punctuation">.</span><span class="token function">Write</span><span class="token punctuation">(</span>lineHt<span class="token punctuation">,</span> <span class="token string">"To find out what's new in this tutorial, click "</span><span class="token punctuation">)</span>
	pdf<span class="token punctuation">.</span><span class="token function">SetFont</span><span class="token punctuation">(</span><span class="token string">""</span><span class="token punctuation">,</span> <span class="token string">"U"</span><span class="token punctuation">,</span> <span class="token number">0</span><span class="token punctuation">)</span>
	link <span class="token operator">:=</span> pdf<span class="token punctuation">.</span><span class="token function">AddLink</span><span class="token punctuation">(</span><span class="token punctuation">)</span>
	pdf<span class="token punctuation">.</span><span class="token function">WriteLinkID</span><span class="token punctuation">(</span>lineHt<span class="token punctuation">,</span> <span class="token string">"here"</span><span class="token punctuation">,</span> link<span class="token punctuation">)</span>
	pdf<span class="token punctuation">.</span><span class="token function">SetFont</span><span class="token punctuation">(</span><span class="token string">""</span><span class="token punctuation">,</span> <span class="token string">""</span><span class="token punctuation">,</span> <span class="token number">0</span><span class="token punctuation">)</span>
	<span class="token comment">// Second page: image link and basic HTML with link</span>
	pdf<span class="token punctuation">.</span><span class="token function">AddPage</span><span class="token punctuation">(</span><span class="token punctuation">)</span>
	pdf<span class="token punctuation">.</span><span class="token function">SetLink</span><span class="token punctuation">(</span>link<span class="token punctuation">,</span> <span class="token number">0</span><span class="token punctuation">,</span> <span class="token operator">-</span><span class="token number">1</span><span class="token punctuation">)</span>
	pdf<span class="token punctuation">.</span><span class="token function">Image</span><span class="token punctuation">(</span>example<span class="token punctuation">.</span><span class="token function">ImageFile</span><span class="token punctuation">(</span><span class="token string">"logo.png"</span><span class="token punctuation">)</span><span class="token punctuation">,</span> <span class="token number">10</span><span class="token punctuation">,</span> <span class="token number">12</span><span class="token punctuation">,</span> <span class="token number">30</span><span class="token punctuation">,</span> <span class="token number">0</span><span class="token punctuation">,</span> <span class="token boolean">false</span><span class="token punctuation">,</span> <span class="token string">""</span><span class="token punctuation">,</span> <span class="token number">0</span><span class="token punctuation">,</span> <span class="token string">"http://www.fpdf.org"</span><span class="token punctuation">)</span>
	pdf<span class="token punctuation">.</span><span class="token function">SetLeftMargin</span><span class="token punctuation">(</span><span class="token number">45</span><span class="token punctuation">)</span>
	pdf<span class="token punctuation">.</span><span class="token function">SetFontSize</span><span class="token punctuation">(</span><span class="token number">14</span><span class="token punctuation">)</span>
	<span class="token boolean">_</span><span class="token punctuation">,</span> lineHt <span class="token operator">=</span> pdf<span class="token punctuation">.</span><span class="token function">GetFontSize</span><span class="token punctuation">(</span><span class="token punctuation">)</span>
	htmlStr <span class="token operator">:=</span> <span class="token string">`You can now easily print text mixing different styles: &lt;b>bold&lt;/b>, `</span> <span class="token operator">+</span>
		<span class="token string">`&lt;i>italic&lt;/i>, &lt;u>underlined&lt;/u>, or &lt;b>&lt;i>&lt;u>all at once&lt;/u>&lt;/i>&lt;/b>!&lt;br>&lt;br>`</span> <span class="token operator">+</span>
		<span class="token string">`&lt;center>You can also center text.&lt;/center>`</span> <span class="token operator">+</span>
		<span class="token string">`&lt;right>Or align it to the right.&lt;/right>`</span> <span class="token operator">+</span>
		<span class="token string">`You can also insert links on text, such as `</span> <span class="token operator">+</span>
		<span class="token string">`&lt;a href="http://www.fpdf.org">www.fpdf.org&lt;/a>, or on an image: click on the logo.`</span>
	html <span class="token operator">:=</span> pdf<span class="token punctuation">.</span><span class="token function">HTMLBasicNew</span><span class="token punctuation">(</span><span class="token punctuation">)</span>
	html<span class="token punctuation">.</span><span class="token function">Write</span><span class="token punctuation">(</span>lineHt<span class="token punctuation">,</span> htmlStr<span class="token punctuation">)</span>
	fileStr <span class="token operator">:=</span> example<span class="token punctuation">.</span><span class="token function">Filename</span><span class="token punctuation">(</span><span class="token string">"Fpdf_HTMLBasicNew"</span><span class="token punctuation">)</span>
	err <span class="token operator">:=</span> pdf<span class="token punctuation">.</span><span class="token function">OutputFileAndClose</span><span class="token punctuation">(</span>fileStr<span class="token punctuation">)</span>
	example<span class="token punctuation">.</span><span class="token function">Summary</span><span class="token punctuation">(</span>err<span class="token punctuation">,</span> fileStr<span class="token punctuation">)</span>
	<span class="token comment">// Output:</span>
	<span class="token comment">// Successfully generated pdf/Fpdf_HTMLBasicNew.pdf</span>
<span class="token punctuation">&#125;</span></code></pre>

<h2 id="演示非标准字体的使用"><a href="#演示非标准字体的使用" class="headerlink" title="演示非标准字体的使用"></a>演示非标准字体的使用</h2><pre class="language-go" data-language="go"><code class="language-go"><span class="token comment">// ExampleFpdf_AddFont demonstrates the use of a non-standard font.</span>
<span class="token keyword">func</span> <span class="token function">ExampleFpdf_AddFont</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">&#123;</span>
	pdf <span class="token operator">:=</span> gofpdf<span class="token punctuation">.</span><span class="token function">New</span><span class="token punctuation">(</span><span class="token string">"P"</span><span class="token punctuation">,</span> <span class="token string">"mm"</span><span class="token punctuation">,</span> <span class="token string">"A4"</span><span class="token punctuation">,</span> example<span class="token punctuation">.</span><span class="token function">FontDir</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">)</span>
	pdf<span class="token punctuation">.</span><span class="token function">AddFont</span><span class="token punctuation">(</span><span class="token string">"Calligrapher"</span><span class="token punctuation">,</span> <span class="token string">""</span><span class="token punctuation">,</span> <span class="token string">"calligra.json"</span><span class="token punctuation">)</span>
	pdf<span class="token punctuation">.</span><span class="token function">AddPage</span><span class="token punctuation">(</span><span class="token punctuation">)</span>
	pdf<span class="token punctuation">.</span><span class="token function">SetFont</span><span class="token punctuation">(</span><span class="token string">"Calligrapher"</span><span class="token punctuation">,</span> <span class="token string">""</span><span class="token punctuation">,</span> <span class="token number">35</span><span class="token punctuation">)</span>
	pdf<span class="token punctuation">.</span><span class="token function">Cell</span><span class="token punctuation">(</span><span class="token number">0</span><span class="token punctuation">,</span> <span class="token number">10</span><span class="token punctuation">,</span> <span class="token string">"Enjoy new fonts with FPDF!"</span><span class="token punctuation">)</span>
	fileStr <span class="token operator">:=</span> example<span class="token punctuation">.</span><span class="token function">Filename</span><span class="token punctuation">(</span><span class="token string">"Fpdf_AddFont"</span><span class="token punctuation">)</span>
	err <span class="token operator">:=</span> pdf<span class="token punctuation">.</span><span class="token function">OutputFileAndClose</span><span class="token punctuation">(</span>fileStr<span class="token punctuation">)</span>
	example<span class="token punctuation">.</span><span class="token function">Summary</span><span class="token punctuation">(</span>err<span class="token punctuation">,</span> fileStr<span class="token punctuation">)</span>
	<span class="token comment">// Output:</span>
	<span class="token comment">// Successfully generated pdf/Fpdf_AddFont.pdf</span>
<span class="token punctuation">&#125;</span></code></pre>

<h2 id="演示如何使用Write函数对齐文本"><a href="#演示如何使用Write函数对齐文本" class="headerlink" title="演示如何使用Write函数对齐文本"></a>演示如何使用Write函数对齐文本</h2><pre class="language-go" data-language="go"><code class="language-go"><span class="token comment">// ExampleFpdf_WriteAligned demonstrates how to align text with the Write function.</span>
<span class="token keyword">func</span> <span class="token function">ExampleFpdf_WriteAligned</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">&#123;</span>
	pdf <span class="token operator">:=</span> gofpdf<span class="token punctuation">.</span><span class="token function">New</span><span class="token punctuation">(</span><span class="token string">"P"</span><span class="token punctuation">,</span> <span class="token string">"mm"</span><span class="token punctuation">,</span> <span class="token string">"A4"</span><span class="token punctuation">,</span> example<span class="token punctuation">.</span><span class="token function">FontDir</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">)</span>
	pdf<span class="token punctuation">.</span><span class="token function">SetLeftMargin</span><span class="token punctuation">(</span><span class="token number">50.0</span><span class="token punctuation">)</span>
	pdf<span class="token punctuation">.</span><span class="token function">SetRightMargin</span><span class="token punctuation">(</span><span class="token number">50.0</span><span class="token punctuation">)</span>
	pdf<span class="token punctuation">.</span><span class="token function">AddPage</span><span class="token punctuation">(</span><span class="token punctuation">)</span>
	pdf<span class="token punctuation">.</span><span class="token function">SetFont</span><span class="token punctuation">(</span><span class="token string">"Helvetica"</span><span class="token punctuation">,</span> <span class="token string">""</span><span class="token punctuation">,</span> <span class="token number">12</span><span class="token punctuation">)</span>
	pdf<span class="token punctuation">.</span><span class="token function">WriteAligned</span><span class="token punctuation">(</span><span class="token number">0</span><span class="token punctuation">,</span> <span class="token number">35</span><span class="token punctuation">,</span> <span class="token string">"This text is the default alignment, Left"</span><span class="token punctuation">,</span> <span class="token string">""</span><span class="token punctuation">)</span>
	pdf<span class="token punctuation">.</span><span class="token function">Ln</span><span class="token punctuation">(</span><span class="token number">35</span><span class="token punctuation">)</span>
	pdf<span class="token punctuation">.</span><span class="token function">WriteAligned</span><span class="token punctuation">(</span><span class="token number">0</span><span class="token punctuation">,</span> <span class="token number">35</span><span class="token punctuation">,</span> <span class="token string">"This text is aligned Left"</span><span class="token punctuation">,</span> <span class="token string">"L"</span><span class="token punctuation">)</span>
	pdf<span class="token punctuation">.</span><span class="token function">Ln</span><span class="token punctuation">(</span><span class="token number">35</span><span class="token punctuation">)</span>
	pdf<span class="token punctuation">.</span><span class="token function">WriteAligned</span><span class="token punctuation">(</span><span class="token number">0</span><span class="token punctuation">,</span> <span class="token number">35</span><span class="token punctuation">,</span> <span class="token string">"This text is aligned Center"</span><span class="token punctuation">,</span> <span class="token string">"C"</span><span class="token punctuation">)</span>
	pdf<span class="token punctuation">.</span><span class="token function">Ln</span><span class="token punctuation">(</span><span class="token number">35</span><span class="token punctuation">)</span>
	pdf<span class="token punctuation">.</span><span class="token function">WriteAligned</span><span class="token punctuation">(</span><span class="token number">0</span><span class="token punctuation">,</span> <span class="token number">35</span><span class="token punctuation">,</span> <span class="token string">"This text is aligned Right"</span><span class="token punctuation">,</span> <span class="token string">"R"</span><span class="token punctuation">)</span>
	pdf<span class="token punctuation">.</span><span class="token function">Ln</span><span class="token punctuation">(</span><span class="token number">35</span><span class="token punctuation">)</span>
	line <span class="token operator">:=</span> <span class="token string">"This can by used to write justified text"</span>
	leftMargin<span class="token punctuation">,</span> <span class="token boolean">_</span><span class="token punctuation">,</span> rightMargin<span class="token punctuation">,</span> <span class="token boolean">_</span> <span class="token operator">:=</span> pdf<span class="token punctuation">.</span><span class="token function">GetMargins</span><span class="token punctuation">(</span><span class="token punctuation">)</span>
	pageWidth<span class="token punctuation">,</span> <span class="token boolean">_</span> <span class="token operator">:=</span> pdf<span class="token punctuation">.</span><span class="token function">GetPageSize</span><span class="token punctuation">(</span><span class="token punctuation">)</span>
	pageWidth <span class="token operator">-=</span> leftMargin <span class="token operator">+</span> rightMargin
	pdf<span class="token punctuation">.</span><span class="token function">SetWordSpacing</span><span class="token punctuation">(</span><span class="token punctuation">(</span>pageWidth <span class="token operator">-</span> pdf<span class="token punctuation">.</span><span class="token function">GetStringWidth</span><span class="token punctuation">(</span>line<span class="token punctuation">)</span><span class="token punctuation">)</span> <span class="token operator">/</span> <span class="token function">float64</span><span class="token punctuation">(</span>strings<span class="token punctuation">.</span><span class="token function">Count</span><span class="token punctuation">(</span>line<span class="token punctuation">,</span> <span class="token string">" "</span><span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">)</span>
	pdf<span class="token punctuation">.</span><span class="token function">WriteAligned</span><span class="token punctuation">(</span>pageWidth<span class="token punctuation">,</span> <span class="token number">35</span><span class="token punctuation">,</span> line<span class="token punctuation">,</span> <span class="token string">"L"</span><span class="token punctuation">)</span>
	fileStr <span class="token operator">:=</span> example<span class="token punctuation">.</span><span class="token function">Filename</span><span class="token punctuation">(</span><span class="token string">"Fpdf_WriteAligned"</span><span class="token punctuation">)</span>
	err <span class="token operator">:=</span> pdf<span class="token punctuation">.</span><span class="token function">OutputFileAndClose</span><span class="token punctuation">(</span>fileStr<span class="token punctuation">)</span>
	example<span class="token punctuation">.</span><span class="token function">Summary</span><span class="token punctuation">(</span>err<span class="token punctuation">,</span> fileStr<span class="token punctuation">)</span>
	<span class="token comment">// Output:</span>
	<span class="token comment">// Successfully generated pdf/Fpdf_WriteAligned.pdf</span>
<span class="token punctuation">&#125;</span></code></pre>

<h2 id="演示如何将图像包含在文档中"><a href="#演示如何将图像包含在文档中" class="headerlink" title="演示如何将图像包含在文档中"></a>演示如何将图像包含在文档中</h2><pre class="language-go" data-language="go"><code class="language-go"><span class="token comment">// ExampleFpdf_Image demonstrates how images are included in documents.</span>
<span class="token keyword">func</span> <span class="token function">ExampleFpdf_Image</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">&#123;</span>
	pdf <span class="token operator">:=</span> gofpdf<span class="token punctuation">.</span><span class="token function">New</span><span class="token punctuation">(</span><span class="token string">"P"</span><span class="token punctuation">,</span> <span class="token string">"mm"</span><span class="token punctuation">,</span> <span class="token string">"A4"</span><span class="token punctuation">,</span> <span class="token string">""</span><span class="token punctuation">)</span>
	pdf<span class="token punctuation">.</span><span class="token function">AddPage</span><span class="token punctuation">(</span><span class="token punctuation">)</span>
	pdf<span class="token punctuation">.</span><span class="token function">SetFont</span><span class="token punctuation">(</span><span class="token string">"Arial"</span><span class="token punctuation">,</span> <span class="token string">""</span><span class="token punctuation">,</span> <span class="token number">11</span><span class="token punctuation">)</span>
	pdf<span class="token punctuation">.</span><span class="token function">Image</span><span class="token punctuation">(</span>example<span class="token punctuation">.</span><span class="token function">ImageFile</span><span class="token punctuation">(</span><span class="token string">"logo.png"</span><span class="token punctuation">)</span><span class="token punctuation">,</span> <span class="token number">10</span><span class="token punctuation">,</span> <span class="token number">10</span><span class="token punctuation">,</span> <span class="token number">30</span><span class="token punctuation">,</span> <span class="token number">0</span><span class="token punctuation">,</span> <span class="token boolean">false</span><span class="token punctuation">,</span> <span class="token string">""</span><span class="token punctuation">,</span> <span class="token number">0</span><span class="token punctuation">,</span> <span class="token string">""</span><span class="token punctuation">)</span>
	pdf<span class="token punctuation">.</span><span class="token function">Text</span><span class="token punctuation">(</span><span class="token number">50</span><span class="token punctuation">,</span> <span class="token number">20</span><span class="token punctuation">,</span> <span class="token string">"logo.png"</span><span class="token punctuation">)</span>
	pdf<span class="token punctuation">.</span><span class="token function">Image</span><span class="token punctuation">(</span>example<span class="token punctuation">.</span><span class="token function">ImageFile</span><span class="token punctuation">(</span><span class="token string">"logo.gif"</span><span class="token punctuation">)</span><span class="token punctuation">,</span> <span class="token number">10</span><span class="token punctuation">,</span> <span class="token number">40</span><span class="token punctuation">,</span> <span class="token number">30</span><span class="token punctuation">,</span> <span class="token number">0</span><span class="token punctuation">,</span> <span class="token boolean">false</span><span class="token punctuation">,</span> <span class="token string">""</span><span class="token punctuation">,</span> <span class="token number">0</span><span class="token punctuation">,</span> <span class="token string">""</span><span class="token punctuation">)</span>
	pdf<span class="token punctuation">.</span><span class="token function">Text</span><span class="token punctuation">(</span><span class="token number">50</span><span class="token punctuation">,</span> <span class="token number">50</span><span class="token punctuation">,</span> <span class="token string">"logo.gif"</span><span class="token punctuation">)</span>
	pdf<span class="token punctuation">.</span><span class="token function">Image</span><span class="token punctuation">(</span>example<span class="token punctuation">.</span><span class="token function">ImageFile</span><span class="token punctuation">(</span><span class="token string">"logo-gray.png"</span><span class="token punctuation">)</span><span class="token punctuation">,</span> <span class="token number">10</span><span class="token punctuation">,</span> <span class="token number">70</span><span class="token punctuation">,</span> <span class="token number">30</span><span class="token punctuation">,</span> <span class="token number">0</span><span class="token punctuation">,</span> <span class="token boolean">false</span><span class="token punctuation">,</span> <span class="token string">""</span><span class="token punctuation">,</span> <span class="token number">0</span><span class="token punctuation">,</span> <span class="token string">""</span><span class="token punctuation">)</span>
	pdf<span class="token punctuation">.</span><span class="token function">Text</span><span class="token punctuation">(</span><span class="token number">50</span><span class="token punctuation">,</span> <span class="token number">80</span><span class="token punctuation">,</span> <span class="token string">"logo-gray.png"</span><span class="token punctuation">)</span>
	pdf<span class="token punctuation">.</span><span class="token function">Image</span><span class="token punctuation">(</span>example<span class="token punctuation">.</span><span class="token function">ImageFile</span><span class="token punctuation">(</span><span class="token string">"logo-rgb.png"</span><span class="token punctuation">)</span><span class="token punctuation">,</span> <span class="token number">10</span><span class="token punctuation">,</span> <span class="token number">100</span><span class="token punctuation">,</span> <span class="token number">30</span><span class="token punctuation">,</span> <span class="token number">0</span><span class="token punctuation">,</span> <span class="token boolean">false</span><span class="token punctuation">,</span> <span class="token string">""</span><span class="token punctuation">,</span> <span class="token number">0</span><span class="token punctuation">,</span> <span class="token string">""</span><span class="token punctuation">)</span>
	pdf<span class="token punctuation">.</span><span class="token function">Text</span><span class="token punctuation">(</span><span class="token number">50</span><span class="token punctuation">,</span> <span class="token number">110</span><span class="token punctuation">,</span> <span class="token string">"logo-rgb.png"</span><span class="token punctuation">)</span>
	pdf<span class="token punctuation">.</span><span class="token function">Image</span><span class="token punctuation">(</span>example<span class="token punctuation">.</span><span class="token function">ImageFile</span><span class="token punctuation">(</span><span class="token string">"logo.jpg"</span><span class="token punctuation">)</span><span class="token punctuation">,</span> <span class="token number">10</span><span class="token punctuation">,</span> <span class="token number">130</span><span class="token punctuation">,</span> <span class="token number">30</span><span class="token punctuation">,</span> <span class="token number">0</span><span class="token punctuation">,</span> <span class="token boolean">false</span><span class="token punctuation">,</span> <span class="token string">""</span><span class="token punctuation">,</span> <span class="token number">0</span><span class="token punctuation">,</span> <span class="token string">""</span><span class="token punctuation">)</span>
	pdf<span class="token punctuation">.</span><span class="token function">Text</span><span class="token punctuation">(</span><span class="token number">50</span><span class="token punctuation">,</span> <span class="token number">140</span><span class="token punctuation">,</span> <span class="token string">"logo.jpg"</span><span class="token punctuation">)</span>
	fileStr <span class="token operator">:=</span> example<span class="token punctuation">.</span><span class="token function">Filename</span><span class="token punctuation">(</span><span class="token string">"Fpdf_Image"</span><span class="token punctuation">)</span>
	err <span class="token operator">:=</span> pdf<span class="token punctuation">.</span><span class="token function">OutputFileAndClose</span><span class="token punctuation">(</span>fileStr<span class="token punctuation">)</span>
	example<span class="token punctuation">.</span><span class="token function">Summary</span><span class="token punctuation">(</span>err<span class="token punctuation">,</span> fileStr<span class="token punctuation">)</span>
	<span class="token comment">// Output:</span>
	<span class="token comment">// Successfully generated pdf/Fpdf_Image.pdf</span>
<span class="token punctuation">&#125;</span></code></pre>

<h2 id="演示了如何使用ImageOption结构体的AllowNegativePosition字段来影响图像的水平位置"><a href="#演示了如何使用ImageOption结构体的AllowNegativePosition字段来影响图像的水平位置" class="headerlink" title="演示了如何使用ImageOption结构体的AllowNegativePosition字段来影响图像的水平位置"></a>演示了如何使用ImageOption结构体的AllowNegativePosition字段来影响图像的水平位置</h2><pre class="language-go" data-language="go"><code class="language-go"><span class="token comment">// ExampleFpdf_ImageOptions demonstrates how the AllowNegativePosition field of the</span>
<span class="token comment">// ImageOption struct can be used to affect horizontal image placement.</span>
<span class="token keyword">func</span> <span class="token function">ExampleFpdf_ImageOptions</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">&#123;</span>
	<span class="token keyword">var</span> opt gofpdf<span class="token punctuation">.</span>ImageOptions

	pdf <span class="token operator">:=</span> gofpdf<span class="token punctuation">.</span><span class="token function">New</span><span class="token punctuation">(</span><span class="token string">"P"</span><span class="token punctuation">,</span> <span class="token string">"mm"</span><span class="token punctuation">,</span> <span class="token string">"A4"</span><span class="token punctuation">,</span> <span class="token string">""</span><span class="token punctuation">)</span>
	pdf<span class="token punctuation">.</span><span class="token function">AddPage</span><span class="token punctuation">(</span><span class="token punctuation">)</span>
	pdf<span class="token punctuation">.</span><span class="token function">SetFont</span><span class="token punctuation">(</span><span class="token string">"Arial"</span><span class="token punctuation">,</span> <span class="token string">""</span><span class="token punctuation">,</span> <span class="token number">11</span><span class="token punctuation">)</span>
	pdf<span class="token punctuation">.</span><span class="token function">SetX</span><span class="token punctuation">(</span><span class="token number">60</span><span class="token punctuation">)</span>
	opt<span class="token punctuation">.</span>ImageType <span class="token operator">=</span> <span class="token string">"png"</span>
	pdf<span class="token punctuation">.</span><span class="token function">ImageOptions</span><span class="token punctuation">(</span>example<span class="token punctuation">.</span><span class="token function">ImageFile</span><span class="token punctuation">(</span><span class="token string">"logo.png"</span><span class="token punctuation">)</span><span class="token punctuation">,</span> <span class="token operator">-</span><span class="token number">10</span><span class="token punctuation">,</span> <span class="token number">10</span><span class="token punctuation">,</span> <span class="token number">30</span><span class="token punctuation">,</span> <span class="token number">0</span><span class="token punctuation">,</span> <span class="token boolean">false</span><span class="token punctuation">,</span> opt<span class="token punctuation">,</span> <span class="token number">0</span><span class="token punctuation">,</span> <span class="token string">""</span><span class="token punctuation">)</span>
	opt<span class="token punctuation">.</span>AllowNegativePosition <span class="token operator">=</span> <span class="token boolean">true</span>
	pdf<span class="token punctuation">.</span><span class="token function">ImageOptions</span><span class="token punctuation">(</span>example<span class="token punctuation">.</span><span class="token function">ImageFile</span><span class="token punctuation">(</span><span class="token string">"logo.png"</span><span class="token punctuation">)</span><span class="token punctuation">,</span> <span class="token operator">-</span><span class="token number">10</span><span class="token punctuation">,</span> <span class="token number">50</span><span class="token punctuation">,</span> <span class="token number">30</span><span class="token punctuation">,</span> <span class="token number">0</span><span class="token punctuation">,</span> <span class="token boolean">false</span><span class="token punctuation">,</span> opt<span class="token punctuation">,</span> <span class="token number">0</span><span class="token punctuation">,</span> <span class="token string">""</span><span class="token punctuation">)</span>
	fileStr <span class="token operator">:=</span> example<span class="token punctuation">.</span><span class="token function">Filename</span><span class="token punctuation">(</span><span class="token string">"Fpdf_ImageOptions"</span><span class="token punctuation">)</span>
	err <span class="token operator">:=</span> pdf<span class="token punctuation">.</span><span class="token function">OutputFileAndClose</span><span class="token punctuation">(</span>fileStr<span class="token punctuation">)</span>
	example<span class="token punctuation">.</span><span class="token function">Summary</span><span class="token punctuation">(</span>err<span class="token punctuation">,</span> fileStr<span class="token punctuation">)</span>
	<span class="token comment">// Output:</span>
	<span class="token comment">// Successfully generated pdf/Fpdf_ImageOptions.pdf</span>
<span class="token punctuation">&#125;</span></code></pre>

<h2 id="演示如何从io加载图像"><a href="#演示如何从io加载图像" class="headerlink" title="演示如何从io加载图像"></a>演示如何从io加载图像</h2><p>Reader(在本例中是一个文件)并将其注册为options</p>
<pre class="language-go" data-language="go"><code class="language-go"><span class="token comment">// ExampleFpdf_RegisterImageOptionsReader demonstrates how to load an image</span>
<span class="token comment">// from a io.Reader (in this case, a file) and register it with options.</span>
<span class="token keyword">func</span> <span class="token function">ExampleFpdf_RegisterImageOptionsReader</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">&#123;</span>
	<span class="token keyword">var</span> <span class="token punctuation">(</span>
		opt    gofpdf<span class="token punctuation">.</span>ImageOptions
		pdfStr <span class="token builtin">string</span>
		fl     <span class="token operator">*</span>os<span class="token punctuation">.</span>File
		err    <span class="token builtin">error</span>
	<span class="token punctuation">)</span>

	pdfStr <span class="token operator">=</span> example<span class="token punctuation">.</span><span class="token function">Filename</span><span class="token punctuation">(</span><span class="token string">"Fpdf_RegisterImageOptionsReader"</span><span class="token punctuation">)</span>
	pdf <span class="token operator">:=</span> gofpdf<span class="token punctuation">.</span><span class="token function">New</span><span class="token punctuation">(</span><span class="token string">"P"</span><span class="token punctuation">,</span> <span class="token string">"mm"</span><span class="token punctuation">,</span> <span class="token string">"A4"</span><span class="token punctuation">,</span> <span class="token string">""</span><span class="token punctuation">)</span>
	pdf<span class="token punctuation">.</span><span class="token function">AddPage</span><span class="token punctuation">(</span><span class="token punctuation">)</span>
	pdf<span class="token punctuation">.</span><span class="token function">SetFont</span><span class="token punctuation">(</span><span class="token string">"Arial"</span><span class="token punctuation">,</span> <span class="token string">""</span><span class="token punctuation">,</span> <span class="token number">11</span><span class="token punctuation">)</span>
	fl<span class="token punctuation">,</span> err <span class="token operator">=</span> os<span class="token punctuation">.</span><span class="token function">Open</span><span class="token punctuation">(</span>example<span class="token punctuation">.</span><span class="token function">ImageFile</span><span class="token punctuation">(</span><span class="token string">"logo.png"</span><span class="token punctuation">)</span><span class="token punctuation">)</span>
	<span class="token keyword">if</span> err <span class="token operator">==</span> <span class="token boolean">nil</span> <span class="token punctuation">&#123;</span>
		opt<span class="token punctuation">.</span>ImageType <span class="token operator">=</span> <span class="token string">"png"</span>
		opt<span class="token punctuation">.</span>AllowNegativePosition <span class="token operator">=</span> <span class="token boolean">true</span>
		<span class="token boolean">_</span> <span class="token operator">=</span> pdf<span class="token punctuation">.</span><span class="token function">RegisterImageOptionsReader</span><span class="token punctuation">(</span><span class="token string">"logo"</span><span class="token punctuation">,</span> opt<span class="token punctuation">,</span> fl<span class="token punctuation">)</span>
		fl<span class="token punctuation">.</span><span class="token function">Close</span><span class="token punctuation">(</span><span class="token punctuation">)</span>
		<span class="token keyword">for</span> x <span class="token operator">:=</span> <span class="token operator">-</span><span class="token number">20.0</span><span class="token punctuation">;</span> x <span class="token operator">&lt;=</span> <span class="token number">40.0</span><span class="token punctuation">;</span> x <span class="token operator">+=</span> <span class="token number">5</span> <span class="token punctuation">&#123;</span>
			pdf<span class="token punctuation">.</span><span class="token function">ImageOptions</span><span class="token punctuation">(</span><span class="token string">"logo"</span><span class="token punctuation">,</span> x<span class="token punctuation">,</span> x<span class="token operator">+</span><span class="token number">30</span><span class="token punctuation">,</span> <span class="token number">0</span><span class="token punctuation">,</span> <span class="token number">0</span><span class="token punctuation">,</span> <span class="token boolean">false</span><span class="token punctuation">,</span> opt<span class="token punctuation">,</span> <span class="token number">0</span><span class="token punctuation">,</span> <span class="token string">""</span><span class="token punctuation">)</span>
		<span class="token punctuation">&#125;</span>
		err <span class="token operator">=</span> pdf<span class="token punctuation">.</span><span class="token function">OutputFileAndClose</span><span class="token punctuation">(</span>pdfStr<span class="token punctuation">)</span>
	<span class="token punctuation">&#125;</span>
	example<span class="token punctuation">.</span><span class="token function">Summary</span><span class="token punctuation">(</span>err<span class="token punctuation">,</span> pdfStr<span class="token punctuation">)</span>
	<span class="token comment">// Output:</span>
	<span class="token comment">// Successfully generated pdf/Fpdf_RegisterImageOptionsReader.pdf</span>
<span class="token punctuation">&#125;</span></code></pre>

<h2 id="演示了带有图像的横向模式"><a href="#演示了带有图像的横向模式" class="headerlink" title="演示了带有图像的横向模式"></a>演示了带有图像的横向模式</h2><pre class="language-go" data-language="go"><code class="language-go"><span class="token comment">// This example demonstrates Landscape mode with images.</span>
<span class="token keyword">func</span> <span class="token function">ExampleFpdf_SetAcceptPageBreakFunc</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">&#123;</span>
	<span class="token keyword">var</span> y0 <span class="token builtin">float64</span>
	<span class="token keyword">var</span> crrntCol <span class="token builtin">int</span>
	loremStr <span class="token operator">:=</span> <span class="token function">lorem</span><span class="token punctuation">(</span><span class="token punctuation">)</span>
	pdf <span class="token operator">:=</span> gofpdf<span class="token punctuation">.</span><span class="token function">New</span><span class="token punctuation">(</span><span class="token string">"L"</span><span class="token punctuation">,</span> <span class="token string">"mm"</span><span class="token punctuation">,</span> <span class="token string">"A4"</span><span class="token punctuation">,</span> <span class="token string">""</span><span class="token punctuation">)</span>
	<span class="token keyword">const</span> <span class="token punctuation">(</span>
		pageWd <span class="token operator">=</span> <span class="token number">297.0</span> <span class="token comment">// A4 210.0 x 297.0</span>
		margin <span class="token operator">=</span> <span class="token number">10.0</span>
		gutter <span class="token operator">=</span> <span class="token number">4</span>
		colNum <span class="token operator">=</span> <span class="token number">3</span>
		colWd  <span class="token operator">=</span> <span class="token punctuation">(</span>pageWd <span class="token operator">-</span> <span class="token number">2</span><span class="token operator">*</span>margin <span class="token operator">-</span> <span class="token punctuation">(</span>colNum<span class="token operator">-</span><span class="token number">1</span><span class="token punctuation">)</span><span class="token operator">*</span>gutter<span class="token punctuation">)</span> <span class="token operator">/</span> colNum
	<span class="token punctuation">)</span>
	setCol <span class="token operator">:=</span> <span class="token keyword">func</span><span class="token punctuation">(</span>col <span class="token builtin">int</span><span class="token punctuation">)</span> <span class="token punctuation">&#123;</span>
		crrntCol <span class="token operator">=</span> col
		x <span class="token operator">:=</span> margin <span class="token operator">+</span> <span class="token function">float64</span><span class="token punctuation">(</span>col<span class="token punctuation">)</span><span class="token operator">*</span><span class="token punctuation">(</span>colWd<span class="token operator">+</span>gutter<span class="token punctuation">)</span>
		pdf<span class="token punctuation">.</span><span class="token function">SetLeftMargin</span><span class="token punctuation">(</span>x<span class="token punctuation">)</span>
		pdf<span class="token punctuation">.</span><span class="token function">SetX</span><span class="token punctuation">(</span>x<span class="token punctuation">)</span>
	<span class="token punctuation">&#125;</span>
	pdf<span class="token punctuation">.</span><span class="token function">SetHeaderFunc</span><span class="token punctuation">(</span><span class="token keyword">func</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">&#123;</span>
		titleStr <span class="token operator">:=</span> <span class="token string">"gofpdf"</span>
		pdf<span class="token punctuation">.</span><span class="token function">SetFont</span><span class="token punctuation">(</span><span class="token string">"Helvetica"</span><span class="token punctuation">,</span> <span class="token string">"B"</span><span class="token punctuation">,</span> <span class="token number">48</span><span class="token punctuation">)</span>
		wd <span class="token operator">:=</span> pdf<span class="token punctuation">.</span><span class="token function">GetStringWidth</span><span class="token punctuation">(</span>titleStr<span class="token punctuation">)</span> <span class="token operator">+</span> <span class="token number">6</span>
		pdf<span class="token punctuation">.</span><span class="token function">SetX</span><span class="token punctuation">(</span><span class="token punctuation">(</span>pageWd <span class="token operator">-</span> wd<span class="token punctuation">)</span> <span class="token operator">/</span> <span class="token number">2</span><span class="token punctuation">)</span>
		pdf<span class="token punctuation">.</span><span class="token function">SetTextColor</span><span class="token punctuation">(</span><span class="token number">128</span><span class="token punctuation">,</span> <span class="token number">128</span><span class="token punctuation">,</span> <span class="token number">160</span><span class="token punctuation">)</span>
		pdf<span class="token punctuation">.</span><span class="token function">Write</span><span class="token punctuation">(</span><span class="token number">12</span><span class="token punctuation">,</span> titleStr<span class="token punctuation">[</span><span class="token punctuation">:</span><span class="token number">2</span><span class="token punctuation">]</span><span class="token punctuation">)</span>
		pdf<span class="token punctuation">.</span><span class="token function">SetTextColor</span><span class="token punctuation">(</span><span class="token number">128</span><span class="token punctuation">,</span> <span class="token number">128</span><span class="token punctuation">,</span> <span class="token number">128</span><span class="token punctuation">)</span>
		pdf<span class="token punctuation">.</span><span class="token function">Write</span><span class="token punctuation">(</span><span class="token number">12</span><span class="token punctuation">,</span> titleStr<span class="token punctuation">[</span><span class="token number">2</span><span class="token punctuation">:</span><span class="token punctuation">]</span><span class="token punctuation">)</span>
		pdf<span class="token punctuation">.</span><span class="token function">Ln</span><span class="token punctuation">(</span><span class="token number">20</span><span class="token punctuation">)</span>
		y0 <span class="token operator">=</span> pdf<span class="token punctuation">.</span><span class="token function">GetY</span><span class="token punctuation">(</span><span class="token punctuation">)</span>
	<span class="token punctuation">&#125;</span><span class="token punctuation">)</span>
	pdf<span class="token punctuation">.</span><span class="token function">SetAcceptPageBreakFunc</span><span class="token punctuation">(</span><span class="token keyword">func</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token builtin">bool</span> <span class="token punctuation">&#123;</span>
		<span class="token keyword">if</span> crrntCol <span class="token operator">&lt;</span> colNum<span class="token operator">-</span><span class="token number">1</span> <span class="token punctuation">&#123;</span>
			<span class="token function">setCol</span><span class="token punctuation">(</span>crrntCol <span class="token operator">+</span> <span class="token number">1</span><span class="token punctuation">)</span>
			pdf<span class="token punctuation">.</span><span class="token function">SetY</span><span class="token punctuation">(</span>y0<span class="token punctuation">)</span>
			<span class="token comment">// Start new column, not new page</span>
			<span class="token keyword">return</span> <span class="token boolean">false</span>
		<span class="token punctuation">&#125;</span>
		<span class="token function">setCol</span><span class="token punctuation">(</span><span class="token number">0</span><span class="token punctuation">)</span>
		<span class="token keyword">return</span> <span class="token boolean">true</span>
	<span class="token punctuation">&#125;</span><span class="token punctuation">)</span>
	pdf<span class="token punctuation">.</span><span class="token function">AddPage</span><span class="token punctuation">(</span><span class="token punctuation">)</span>
	pdf<span class="token punctuation">.</span><span class="token function">SetFont</span><span class="token punctuation">(</span><span class="token string">"Times"</span><span class="token punctuation">,</span> <span class="token string">""</span><span class="token punctuation">,</span> <span class="token number">12</span><span class="token punctuation">)</span>
	<span class="token keyword">for</span> j <span class="token operator">:=</span> <span class="token number">0</span><span class="token punctuation">;</span> j <span class="token operator">&lt;</span> <span class="token number">20</span><span class="token punctuation">;</span> j<span class="token operator">++</span> <span class="token punctuation">&#123;</span>
		<span class="token keyword">if</span> j <span class="token operator">==</span> <span class="token number">1</span> <span class="token punctuation">&#123;</span>
			pdf<span class="token punctuation">.</span><span class="token function">Image</span><span class="token punctuation">(</span>example<span class="token punctuation">.</span><span class="token function">ImageFile</span><span class="token punctuation">(</span><span class="token string">"fpdf.png"</span><span class="token punctuation">)</span><span class="token punctuation">,</span> <span class="token operator">-</span><span class="token number">1</span><span class="token punctuation">,</span> <span class="token number">0</span><span class="token punctuation">,</span> colWd<span class="token punctuation">,</span> <span class="token number">0</span><span class="token punctuation">,</span> <span class="token boolean">true</span><span class="token punctuation">,</span> <span class="token string">""</span><span class="token punctuation">,</span> <span class="token number">0</span><span class="token punctuation">,</span> <span class="token string">""</span><span class="token punctuation">)</span>
		<span class="token punctuation">&#125;</span> <span class="token keyword">else</span> <span class="token keyword">if</span> j <span class="token operator">==</span> <span class="token number">5</span> <span class="token punctuation">&#123;</span>
			pdf<span class="token punctuation">.</span><span class="token function">Image</span><span class="token punctuation">(</span>example<span class="token punctuation">.</span><span class="token function">ImageFile</span><span class="token punctuation">(</span><span class="token string">"golang-gopher.png"</span><span class="token punctuation">)</span><span class="token punctuation">,</span>
				<span class="token operator">-</span><span class="token number">1</span><span class="token punctuation">,</span> <span class="token number">0</span><span class="token punctuation">,</span> colWd<span class="token punctuation">,</span> <span class="token number">0</span><span class="token punctuation">,</span> <span class="token boolean">true</span><span class="token punctuation">,</span> <span class="token string">""</span><span class="token punctuation">,</span> <span class="token number">0</span><span class="token punctuation">,</span> <span class="token string">""</span><span class="token punctuation">)</span>
		<span class="token punctuation">&#125;</span>
		pdf<span class="token punctuation">.</span><span class="token function">MultiCell</span><span class="token punctuation">(</span>colWd<span class="token punctuation">,</span> <span class="token number">5</span><span class="token punctuation">,</span> loremStr<span class="token punctuation">,</span> <span class="token string">""</span><span class="token punctuation">,</span> <span class="token string">""</span><span class="token punctuation">,</span> <span class="token boolean">false</span><span class="token punctuation">)</span>
		pdf<span class="token punctuation">.</span><span class="token function">Ln</span><span class="token punctuation">(</span><span class="token operator">-</span><span class="token number">1</span><span class="token punctuation">)</span>
	<span class="token punctuation">&#125;</span>
	fileStr <span class="token operator">:=</span> example<span class="token punctuation">.</span><span class="token function">Filename</span><span class="token punctuation">(</span><span class="token string">"Fpdf_SetAcceptPageBreakFunc_landscape"</span><span class="token punctuation">)</span>
	err <span class="token operator">:=</span> pdf<span class="token punctuation">.</span><span class="token function">OutputFileAndClose</span><span class="token punctuation">(</span>fileStr<span class="token punctuation">)</span>
	example<span class="token punctuation">.</span><span class="token function">Summary</span><span class="token punctuation">(</span>err<span class="token punctuation">,</span> fileStr<span class="token punctuation">)</span>
	<span class="token comment">// Output:</span>
	<span class="token comment">// Successfully generated pdf/Fpdf_SetAcceptPageBreakFunc_landscape.pdf</span>
<span class="token punctuation">&#125;</span></code></pre>

<h2 id="演示各种几何图形的构造"><a href="#演示各种几何图形的构造" class="headerlink" title="演示各种几何图形的构造"></a>演示各种几何图形的构造</h2><pre class="language-go" data-language="go"><code class="language-go"><span class="token comment">// ExampleFpdf_Circle demonstrates the construction of various geometric figures,</span>
<span class="token keyword">func</span> <span class="token function">ExampleFpdf_Circle</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">&#123;</span>
	<span class="token keyword">const</span> <span class="token punctuation">(</span>
		thin  <span class="token operator">=</span> <span class="token number">0.2</span>
		thick <span class="token operator">=</span> <span class="token number">3.0</span>
	<span class="token punctuation">)</span>
	pdf <span class="token operator">:=</span> gofpdf<span class="token punctuation">.</span><span class="token function">New</span><span class="token punctuation">(</span><span class="token string">""</span><span class="token punctuation">,</span> <span class="token string">""</span><span class="token punctuation">,</span> <span class="token string">""</span><span class="token punctuation">,</span> <span class="token string">""</span><span class="token punctuation">)</span>
	pdf<span class="token punctuation">.</span><span class="token function">SetFont</span><span class="token punctuation">(</span><span class="token string">"Helvetica"</span><span class="token punctuation">,</span> <span class="token string">""</span><span class="token punctuation">,</span> <span class="token number">12</span><span class="token punctuation">)</span>
	pdf<span class="token punctuation">.</span><span class="token function">SetFillColor</span><span class="token punctuation">(</span><span class="token number">200</span><span class="token punctuation">,</span> <span class="token number">200</span><span class="token punctuation">,</span> <span class="token number">220</span><span class="token punctuation">)</span>
	pdf<span class="token punctuation">.</span><span class="token function">AddPage</span><span class="token punctuation">(</span><span class="token punctuation">)</span>

	y <span class="token operator">:=</span> <span class="token number">15.0</span>
	pdf<span class="token punctuation">.</span><span class="token function">Text</span><span class="token punctuation">(</span><span class="token number">10</span><span class="token punctuation">,</span> y<span class="token punctuation">,</span> <span class="token string">"Circles"</span><span class="token punctuation">)</span>
	pdf<span class="token punctuation">.</span><span class="token function">SetFillColor</span><span class="token punctuation">(</span><span class="token number">200</span><span class="token punctuation">,</span> <span class="token number">200</span><span class="token punctuation">,</span> <span class="token number">220</span><span class="token punctuation">)</span>
	pdf<span class="token punctuation">.</span><span class="token function">SetLineWidth</span><span class="token punctuation">(</span>thin<span class="token punctuation">)</span>
	pdf<span class="token punctuation">.</span><span class="token function">Circle</span><span class="token punctuation">(</span><span class="token number">20</span><span class="token punctuation">,</span> y<span class="token operator">+</span><span class="token number">15</span><span class="token punctuation">,</span> <span class="token number">10</span><span class="token punctuation">,</span> <span class="token string">"D"</span><span class="token punctuation">)</span>
	pdf<span class="token punctuation">.</span><span class="token function">Circle</span><span class="token punctuation">(</span><span class="token number">45</span><span class="token punctuation">,</span> y<span class="token operator">+</span><span class="token number">15</span><span class="token punctuation">,</span> <span class="token number">10</span><span class="token punctuation">,</span> <span class="token string">"F"</span><span class="token punctuation">)</span>
	pdf<span class="token punctuation">.</span><span class="token function">Circle</span><span class="token punctuation">(</span><span class="token number">70</span><span class="token punctuation">,</span> y<span class="token operator">+</span><span class="token number">15</span><span class="token punctuation">,</span> <span class="token number">10</span><span class="token punctuation">,</span> <span class="token string">"FD"</span><span class="token punctuation">)</span>
	pdf<span class="token punctuation">.</span><span class="token function">SetLineWidth</span><span class="token punctuation">(</span>thick<span class="token punctuation">)</span>
	pdf<span class="token punctuation">.</span><span class="token function">Circle</span><span class="token punctuation">(</span><span class="token number">95</span><span class="token punctuation">,</span> y<span class="token operator">+</span><span class="token number">15</span><span class="token punctuation">,</span> <span class="token number">10</span><span class="token punctuation">,</span> <span class="token string">"FD"</span><span class="token punctuation">)</span>
	pdf<span class="token punctuation">.</span><span class="token function">SetLineWidth</span><span class="token punctuation">(</span>thin<span class="token punctuation">)</span>

	y <span class="token operator">+=</span> <span class="token number">40.0</span>
	pdf<span class="token punctuation">.</span><span class="token function">Text</span><span class="token punctuation">(</span><span class="token number">10</span><span class="token punctuation">,</span> y<span class="token punctuation">,</span> <span class="token string">"Ellipses"</span><span class="token punctuation">)</span>
	pdf<span class="token punctuation">.</span><span class="token function">SetFillColor</span><span class="token punctuation">(</span><span class="token number">220</span><span class="token punctuation">,</span> <span class="token number">200</span><span class="token punctuation">,</span> <span class="token number">200</span><span class="token punctuation">)</span>
	pdf<span class="token punctuation">.</span><span class="token function">Ellipse</span><span class="token punctuation">(</span><span class="token number">30</span><span class="token punctuation">,</span> y<span class="token operator">+</span><span class="token number">15</span><span class="token punctuation">,</span> <span class="token number">20</span><span class="token punctuation">,</span> <span class="token number">10</span><span class="token punctuation">,</span> <span class="token number">0</span><span class="token punctuation">,</span> <span class="token string">"D"</span><span class="token punctuation">)</span>
	pdf<span class="token punctuation">.</span><span class="token function">Ellipse</span><span class="token punctuation">(</span><span class="token number">75</span><span class="token punctuation">,</span> y<span class="token operator">+</span><span class="token number">15</span><span class="token punctuation">,</span> <span class="token number">20</span><span class="token punctuation">,</span> <span class="token number">10</span><span class="token punctuation">,</span> <span class="token number">0</span><span class="token punctuation">,</span> <span class="token string">"F"</span><span class="token punctuation">)</span>
	pdf<span class="token punctuation">.</span><span class="token function">Ellipse</span><span class="token punctuation">(</span><span class="token number">120</span><span class="token punctuation">,</span> y<span class="token operator">+</span><span class="token number">15</span><span class="token punctuation">,</span> <span class="token number">20</span><span class="token punctuation">,</span> <span class="token number">10</span><span class="token punctuation">,</span> <span class="token number">0</span><span class="token punctuation">,</span> <span class="token string">"FD"</span><span class="token punctuation">)</span>
	pdf<span class="token punctuation">.</span><span class="token function">SetLineWidth</span><span class="token punctuation">(</span>thick<span class="token punctuation">)</span>
	pdf<span class="token punctuation">.</span><span class="token function">Ellipse</span><span class="token punctuation">(</span><span class="token number">165</span><span class="token punctuation">,</span> y<span class="token operator">+</span><span class="token number">15</span><span class="token punctuation">,</span> <span class="token number">20</span><span class="token punctuation">,</span> <span class="token number">10</span><span class="token punctuation">,</span> <span class="token number">0</span><span class="token punctuation">,</span> <span class="token string">"FD"</span><span class="token punctuation">)</span>
	pdf<span class="token punctuation">.</span><span class="token function">SetLineWidth</span><span class="token punctuation">(</span>thin<span class="token punctuation">)</span>

	y <span class="token operator">+=</span> <span class="token number">40.0</span>
	pdf<span class="token punctuation">.</span><span class="token function">Text</span><span class="token punctuation">(</span><span class="token number">10</span><span class="token punctuation">,</span> y<span class="token punctuation">,</span> <span class="token string">"Curves (quadratic)"</span><span class="token punctuation">)</span>
	pdf<span class="token punctuation">.</span><span class="token function">SetFillColor</span><span class="token punctuation">(</span><span class="token number">220</span><span class="token punctuation">,</span> <span class="token number">220</span><span class="token punctuation">,</span> <span class="token number">200</span><span class="token punctuation">)</span>
	pdf<span class="token punctuation">.</span><span class="token function">Curve</span><span class="token punctuation">(</span><span class="token number">10</span><span class="token punctuation">,</span> y<span class="token operator">+</span><span class="token number">30</span><span class="token punctuation">,</span> <span class="token number">15</span><span class="token punctuation">,</span> y<span class="token operator">-</span><span class="token number">20</span><span class="token punctuation">,</span> <span class="token number">40</span><span class="token punctuation">,</span> y<span class="token operator">+</span><span class="token number">30</span><span class="token punctuation">,</span> <span class="token string">"D"</span><span class="token punctuation">)</span>
	pdf<span class="token punctuation">.</span><span class="token function">Curve</span><span class="token punctuation">(</span><span class="token number">45</span><span class="token punctuation">,</span> y<span class="token operator">+</span><span class="token number">30</span><span class="token punctuation">,</span> <span class="token number">50</span><span class="token punctuation">,</span> y<span class="token operator">-</span><span class="token number">20</span><span class="token punctuation">,</span> <span class="token number">75</span><span class="token punctuation">,</span> y<span class="token operator">+</span><span class="token number">30</span><span class="token punctuation">,</span> <span class="token string">"F"</span><span class="token punctuation">)</span>
	pdf<span class="token punctuation">.</span><span class="token function">Curve</span><span class="token punctuation">(</span><span class="token number">80</span><span class="token punctuation">,</span> y<span class="token operator">+</span><span class="token number">30</span><span class="token punctuation">,</span> <span class="token number">85</span><span class="token punctuation">,</span> y<span class="token operator">-</span><span class="token number">20</span><span class="token punctuation">,</span> <span class="token number">110</span><span class="token punctuation">,</span> y<span class="token operator">+</span><span class="token number">30</span><span class="token punctuation">,</span> <span class="token string">"FD"</span><span class="token punctuation">)</span>
	pdf<span class="token punctuation">.</span><span class="token function">SetLineWidth</span><span class="token punctuation">(</span>thick<span class="token punctuation">)</span>
	pdf<span class="token punctuation">.</span><span class="token function">Curve</span><span class="token punctuation">(</span><span class="token number">115</span><span class="token punctuation">,</span> y<span class="token operator">+</span><span class="token number">30</span><span class="token punctuation">,</span> <span class="token number">120</span><span class="token punctuation">,</span> y<span class="token operator">-</span><span class="token number">20</span><span class="token punctuation">,</span> <span class="token number">145</span><span class="token punctuation">,</span> y<span class="token operator">+</span><span class="token number">30</span><span class="token punctuation">,</span> <span class="token string">"FD"</span><span class="token punctuation">)</span>
	pdf<span class="token punctuation">.</span><span class="token function">SetLineCapStyle</span><span class="token punctuation">(</span><span class="token string">"round"</span><span class="token punctuation">)</span>
	pdf<span class="token punctuation">.</span><span class="token function">Curve</span><span class="token punctuation">(</span><span class="token number">150</span><span class="token punctuation">,</span> y<span class="token operator">+</span><span class="token number">30</span><span class="token punctuation">,</span> <span class="token number">155</span><span class="token punctuation">,</span> y<span class="token operator">-</span><span class="token number">20</span><span class="token punctuation">,</span> <span class="token number">180</span><span class="token punctuation">,</span> y<span class="token operator">+</span><span class="token number">30</span><span class="token punctuation">,</span> <span class="token string">"FD"</span><span class="token punctuation">)</span>
	pdf<span class="token punctuation">.</span><span class="token function">SetLineWidth</span><span class="token punctuation">(</span>thin<span class="token punctuation">)</span>
	pdf<span class="token punctuation">.</span><span class="token function">SetLineCapStyle</span><span class="token punctuation">(</span><span class="token string">"butt"</span><span class="token punctuation">)</span>

	y <span class="token operator">+=</span> <span class="token number">40.0</span>
	pdf<span class="token punctuation">.</span><span class="token function">Text</span><span class="token punctuation">(</span><span class="token number">10</span><span class="token punctuation">,</span> y<span class="token punctuation">,</span> <span class="token string">"Curves (cubic)"</span><span class="token punctuation">)</span>
	pdf<span class="token punctuation">.</span><span class="token function">SetFillColor</span><span class="token punctuation">(</span><span class="token number">220</span><span class="token punctuation">,</span> <span class="token number">200</span><span class="token punctuation">,</span> <span class="token number">220</span><span class="token punctuation">)</span>
	pdf<span class="token punctuation">.</span><span class="token function">CurveBezierCubic</span><span class="token punctuation">(</span><span class="token number">10</span><span class="token punctuation">,</span> y<span class="token operator">+</span><span class="token number">30</span><span class="token punctuation">,</span> <span class="token number">15</span><span class="token punctuation">,</span> y<span class="token operator">-</span><span class="token number">20</span><span class="token punctuation">,</span> <span class="token number">10</span><span class="token punctuation">,</span> y<span class="token operator">+</span><span class="token number">30</span><span class="token punctuation">,</span> <span class="token number">40</span><span class="token punctuation">,</span> y<span class="token operator">+</span><span class="token number">30</span><span class="token punctuation">,</span> <span class="token string">"D"</span><span class="token punctuation">)</span>
	pdf<span class="token punctuation">.</span><span class="token function">CurveBezierCubic</span><span class="token punctuation">(</span><span class="token number">45</span><span class="token punctuation">,</span> y<span class="token operator">+</span><span class="token number">30</span><span class="token punctuation">,</span> <span class="token number">50</span><span class="token punctuation">,</span> y<span class="token operator">-</span><span class="token number">20</span><span class="token punctuation">,</span> <span class="token number">45</span><span class="token punctuation">,</span> y<span class="token operator">+</span><span class="token number">30</span><span class="token punctuation">,</span> <span class="token number">75</span><span class="token punctuation">,</span> y<span class="token operator">+</span><span class="token number">30</span><span class="token punctuation">,</span> <span class="token string">"F"</span><span class="token punctuation">)</span>
	pdf<span class="token punctuation">.</span><span class="token function">CurveBezierCubic</span><span class="token punctuation">(</span><span class="token number">80</span><span class="token punctuation">,</span> y<span class="token operator">+</span><span class="token number">30</span><span class="token punctuation">,</span> <span class="token number">85</span><span class="token punctuation">,</span> y<span class="token operator">-</span><span class="token number">20</span><span class="token punctuation">,</span> <span class="token number">80</span><span class="token punctuation">,</span> y<span class="token operator">+</span><span class="token number">30</span><span class="token punctuation">,</span> <span class="token number">110</span><span class="token punctuation">,</span> y<span class="token operator">+</span><span class="token number">30</span><span class="token punctuation">,</span> <span class="token string">"FD"</span><span class="token punctuation">)</span>
	pdf<span class="token punctuation">.</span><span class="token function">SetLineWidth</span><span class="token punctuation">(</span>thick<span class="token punctuation">)</span>
	pdf<span class="token punctuation">.</span><span class="token function">CurveBezierCubic</span><span class="token punctuation">(</span><span class="token number">115</span><span class="token punctuation">,</span> y<span class="token operator">+</span><span class="token number">30</span><span class="token punctuation">,</span> <span class="token number">120</span><span class="token punctuation">,</span> y<span class="token operator">-</span><span class="token number">20</span><span class="token punctuation">,</span> <span class="token number">115</span><span class="token punctuation">,</span> y<span class="token operator">+</span><span class="token number">30</span><span class="token punctuation">,</span> <span class="token number">145</span><span class="token punctuation">,</span> y<span class="token operator">+</span><span class="token number">30</span><span class="token punctuation">,</span> <span class="token string">"FD"</span><span class="token punctuation">)</span>
	pdf<span class="token punctuation">.</span><span class="token function">SetLineCapStyle</span><span class="token punctuation">(</span><span class="token string">"round"</span><span class="token punctuation">)</span>
	pdf<span class="token punctuation">.</span><span class="token function">CurveBezierCubic</span><span class="token punctuation">(</span><span class="token number">150</span><span class="token punctuation">,</span> y<span class="token operator">+</span><span class="token number">30</span><span class="token punctuation">,</span> <span class="token number">155</span><span class="token punctuation">,</span> y<span class="token operator">-</span><span class="token number">20</span><span class="token punctuation">,</span> <span class="token number">150</span><span class="token punctuation">,</span> y<span class="token operator">+</span><span class="token number">30</span><span class="token punctuation">,</span> <span class="token number">180</span><span class="token punctuation">,</span> y<span class="token operator">+</span><span class="token number">30</span><span class="token punctuation">,</span> <span class="token string">"FD"</span><span class="token punctuation">)</span>
	pdf<span class="token punctuation">.</span><span class="token function">SetLineWidth</span><span class="token punctuation">(</span>thin<span class="token punctuation">)</span>
	pdf<span class="token punctuation">.</span><span class="token function">SetLineCapStyle</span><span class="token punctuation">(</span><span class="token string">"butt"</span><span class="token punctuation">)</span>

	y <span class="token operator">+=</span> <span class="token number">40.0</span>
	pdf<span class="token punctuation">.</span><span class="token function">Text</span><span class="token punctuation">(</span><span class="token number">10</span><span class="token punctuation">,</span> y<span class="token punctuation">,</span> <span class="token string">"Arcs"</span><span class="token punctuation">)</span>
	pdf<span class="token punctuation">.</span><span class="token function">SetFillColor</span><span class="token punctuation">(</span><span class="token number">200</span><span class="token punctuation">,</span> <span class="token number">220</span><span class="token punctuation">,</span> <span class="token number">220</span><span class="token punctuation">)</span>
	pdf<span class="token punctuation">.</span><span class="token function">SetLineWidth</span><span class="token punctuation">(</span>thick<span class="token punctuation">)</span>
	pdf<span class="token punctuation">.</span><span class="token function">Arc</span><span class="token punctuation">(</span><span class="token number">45</span><span class="token punctuation">,</span> y<span class="token operator">+</span><span class="token number">35</span><span class="token punctuation">,</span> <span class="token number">20</span><span class="token punctuation">,</span> <span class="token number">10</span><span class="token punctuation">,</span> <span class="token number">0</span><span class="token punctuation">,</span> <span class="token number">0</span><span class="token punctuation">,</span> <span class="token number">180</span><span class="token punctuation">,</span> <span class="token string">"FD"</span><span class="token punctuation">)</span>
	pdf<span class="token punctuation">.</span><span class="token function">SetLineWidth</span><span class="token punctuation">(</span>thin<span class="token punctuation">)</span>
	pdf<span class="token punctuation">.</span><span class="token function">Arc</span><span class="token punctuation">(</span><span class="token number">45</span><span class="token punctuation">,</span> y<span class="token operator">+</span><span class="token number">35</span><span class="token punctuation">,</span> <span class="token number">25</span><span class="token punctuation">,</span> <span class="token number">15</span><span class="token punctuation">,</span> <span class="token number">0</span><span class="token punctuation">,</span> <span class="token number">90</span><span class="token punctuation">,</span> <span class="token number">270</span><span class="token punctuation">,</span> <span class="token string">"D"</span><span class="token punctuation">)</span>
	pdf<span class="token punctuation">.</span><span class="token function">SetLineWidth</span><span class="token punctuation">(</span>thick<span class="token punctuation">)</span>
	pdf<span class="token punctuation">.</span><span class="token function">Arc</span><span class="token punctuation">(</span><span class="token number">45</span><span class="token punctuation">,</span> y<span class="token operator">+</span><span class="token number">35</span><span class="token punctuation">,</span> <span class="token number">30</span><span class="token punctuation">,</span> <span class="token number">20</span><span class="token punctuation">,</span> <span class="token number">0</span><span class="token punctuation">,</span> <span class="token number">0</span><span class="token punctuation">,</span> <span class="token number">360</span><span class="token punctuation">,</span> <span class="token string">"D"</span><span class="token punctuation">)</span>
	pdf<span class="token punctuation">.</span><span class="token function">SetLineCapStyle</span><span class="token punctuation">(</span><span class="token string">"round"</span><span class="token punctuation">)</span>
	pdf<span class="token punctuation">.</span><span class="token function">Arc</span><span class="token punctuation">(</span><span class="token number">135</span><span class="token punctuation">,</span> y<span class="token operator">+</span><span class="token number">35</span><span class="token punctuation">,</span> <span class="token number">20</span><span class="token punctuation">,</span> <span class="token number">10</span><span class="token punctuation">,</span> <span class="token number">135</span><span class="token punctuation">,</span> <span class="token number">0</span><span class="token punctuation">,</span> <span class="token number">180</span><span class="token punctuation">,</span> <span class="token string">"FD"</span><span class="token punctuation">)</span>
	pdf<span class="token punctuation">.</span><span class="token function">SetLineWidth</span><span class="token punctuation">(</span>thin<span class="token punctuation">)</span>
	pdf<span class="token punctuation">.</span><span class="token function">Arc</span><span class="token punctuation">(</span><span class="token number">135</span><span class="token punctuation">,</span> y<span class="token operator">+</span><span class="token number">35</span><span class="token punctuation">,</span> <span class="token number">25</span><span class="token punctuation">,</span> <span class="token number">15</span><span class="token punctuation">,</span> <span class="token number">135</span><span class="token punctuation">,</span> <span class="token number">90</span><span class="token punctuation">,</span> <span class="token number">270</span><span class="token punctuation">,</span> <span class="token string">"D"</span><span class="token punctuation">)</span>
	pdf<span class="token punctuation">.</span><span class="token function">SetLineWidth</span><span class="token punctuation">(</span>thick<span class="token punctuation">)</span>
	pdf<span class="token punctuation">.</span><span class="token function">Arc</span><span class="token punctuation">(</span><span class="token number">135</span><span class="token punctuation">,</span> y<span class="token operator">+</span><span class="token number">35</span><span class="token punctuation">,</span> <span class="token number">30</span><span class="token punctuation">,</span> <span class="token number">20</span><span class="token punctuation">,</span> <span class="token number">135</span><span class="token punctuation">,</span> <span class="token number">0</span><span class="token punctuation">,</span> <span class="token number">360</span><span class="token punctuation">,</span> <span class="token string">"D"</span><span class="token punctuation">)</span>
	pdf<span class="token punctuation">.</span><span class="token function">SetLineWidth</span><span class="token punctuation">(</span>thin<span class="token punctuation">)</span>
	pdf<span class="token punctuation">.</span><span class="token function">SetLineCapStyle</span><span class="token punctuation">(</span><span class="token string">"butt"</span><span class="token punctuation">)</span>

	fileStr <span class="token operator">:=</span> example<span class="token punctuation">.</span><span class="token function">Filename</span><span class="token punctuation">(</span><span class="token string">"Fpdf_Circle_figures"</span><span class="token punctuation">)</span>
	err <span class="token operator">:=</span> pdf<span class="token punctuation">.</span><span class="token function">OutputFileAndClose</span><span class="token punctuation">(</span>fileStr<span class="token punctuation">)</span>
	example<span class="token punctuation">.</span><span class="token function">Summary</span><span class="token punctuation">(</span>err<span class="token punctuation">,</span> fileStr<span class="token punctuation">)</span>
	<span class="token comment">// Output:</span>
	<span class="token comment">// Successfully generated pdf/Fpdf_Circle_figures.pdf</span>
<span class="token punctuation">&#125;</span></code></pre>

<h2 id="演示alpha透明度"><a href="#演示alpha透明度" class="headerlink" title="演示alpha透明度"></a>演示alpha透明度</h2><pre class="language-go" data-language="go"><code class="language-go"><span class="token keyword">func</span> <span class="token function">ExampleFpdf_SetAlpha</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">&#123;</span>
	<span class="token keyword">const</span> <span class="token punctuation">(</span>
		gapX  <span class="token operator">=</span> <span class="token number">10.0</span>
		gapY  <span class="token operator">=</span> <span class="token number">9.0</span>
		rectW <span class="token operator">=</span> <span class="token number">40.0</span>
		rectH <span class="token operator">=</span> <span class="token number">58.0</span>
		pageW <span class="token operator">=</span> <span class="token number">210</span>
		pageH <span class="token operator">=</span> <span class="token number">297</span>
	<span class="token punctuation">)</span>
	modeList <span class="token operator">:=</span> <span class="token punctuation">[</span><span class="token punctuation">]</span><span class="token builtin">string</span><span class="token punctuation">&#123;</span><span class="token string">"Normal"</span><span class="token punctuation">,</span> <span class="token string">"Multiply"</span><span class="token punctuation">,</span> <span class="token string">"Screen"</span><span class="token punctuation">,</span> <span class="token string">"Overlay"</span><span class="token punctuation">,</span>
		<span class="token string">"Darken"</span><span class="token punctuation">,</span> <span class="token string">"Lighten"</span><span class="token punctuation">,</span> <span class="token string">"ColorDodge"</span><span class="token punctuation">,</span> <span class="token string">"ColorBurn"</span><span class="token punctuation">,</span> <span class="token string">"HardLight"</span><span class="token punctuation">,</span> <span class="token string">"SoftLight"</span><span class="token punctuation">,</span>
		<span class="token string">"Difference"</span><span class="token punctuation">,</span> <span class="token string">"Exclusion"</span><span class="token punctuation">,</span> <span class="token string">"Hue"</span><span class="token punctuation">,</span> <span class="token string">"Saturation"</span><span class="token punctuation">,</span> <span class="token string">"Color"</span><span class="token punctuation">,</span> <span class="token string">"Luminosity"</span><span class="token punctuation">&#125;</span>
	pdf <span class="token operator">:=</span> gofpdf<span class="token punctuation">.</span><span class="token function">New</span><span class="token punctuation">(</span><span class="token string">""</span><span class="token punctuation">,</span> <span class="token string">""</span><span class="token punctuation">,</span> <span class="token string">""</span><span class="token punctuation">,</span> <span class="token string">""</span><span class="token punctuation">)</span>
	pdf<span class="token punctuation">.</span><span class="token function">SetLineWidth</span><span class="token punctuation">(</span><span class="token number">2</span><span class="token punctuation">)</span>
	pdf<span class="token punctuation">.</span><span class="token function">SetAutoPageBreak</span><span class="token punctuation">(</span><span class="token boolean">false</span><span class="token punctuation">,</span> <span class="token number">0</span><span class="token punctuation">)</span>
	pdf<span class="token punctuation">.</span><span class="token function">AddPage</span><span class="token punctuation">(</span><span class="token punctuation">)</span>
	pdf<span class="token punctuation">.</span><span class="token function">SetFont</span><span class="token punctuation">(</span><span class="token string">"Helvetica"</span><span class="token punctuation">,</span> <span class="token string">""</span><span class="token punctuation">,</span> <span class="token number">18</span><span class="token punctuation">)</span>
	pdf<span class="token punctuation">.</span><span class="token function">SetXY</span><span class="token punctuation">(</span><span class="token number">0</span><span class="token punctuation">,</span> gapY<span class="token punctuation">)</span>
	pdf<span class="token punctuation">.</span><span class="token function">SetTextColor</span><span class="token punctuation">(</span><span class="token number">0</span><span class="token punctuation">,</span> <span class="token number">0</span><span class="token punctuation">,</span> <span class="token number">0</span><span class="token punctuation">)</span>
	pdf<span class="token punctuation">.</span><span class="token function">CellFormat</span><span class="token punctuation">(</span>pageW<span class="token punctuation">,</span> gapY<span class="token punctuation">,</span> <span class="token string">"Alpha Blending Modes"</span><span class="token punctuation">,</span> <span class="token string">""</span><span class="token punctuation">,</span> <span class="token number">0</span><span class="token punctuation">,</span> <span class="token string">"C"</span><span class="token punctuation">,</span> <span class="token boolean">false</span><span class="token punctuation">,</span> <span class="token number">0</span><span class="token punctuation">,</span> <span class="token string">""</span><span class="token punctuation">)</span>
	j <span class="token operator">:=</span> <span class="token number">0</span>
	y <span class="token operator">:=</span> <span class="token number">3</span> <span class="token operator">*</span> gapY
	<span class="token keyword">for</span> col <span class="token operator">:=</span> <span class="token number">0</span><span class="token punctuation">;</span> col <span class="token operator">&lt;</span> <span class="token number">4</span><span class="token punctuation">;</span> col<span class="token operator">++</span> <span class="token punctuation">&#123;</span>
		x <span class="token operator">:=</span> gapX
		<span class="token keyword">for</span> row <span class="token operator">:=</span> <span class="token number">0</span><span class="token punctuation">;</span> row <span class="token operator">&lt;</span> <span class="token number">4</span><span class="token punctuation">;</span> row<span class="token operator">++</span> <span class="token punctuation">&#123;</span>
			pdf<span class="token punctuation">.</span><span class="token function">Rect</span><span class="token punctuation">(</span>x<span class="token punctuation">,</span> y<span class="token punctuation">,</span> rectW<span class="token punctuation">,</span> rectH<span class="token punctuation">,</span> <span class="token string">"D"</span><span class="token punctuation">)</span>
			pdf<span class="token punctuation">.</span><span class="token function">SetFont</span><span class="token punctuation">(</span><span class="token string">"Helvetica"</span><span class="token punctuation">,</span> <span class="token string">"B"</span><span class="token punctuation">,</span> <span class="token number">12</span><span class="token punctuation">)</span>
			pdf<span class="token punctuation">.</span><span class="token function">SetFillColor</span><span class="token punctuation">(</span><span class="token number">0</span><span class="token punctuation">,</span> <span class="token number">0</span><span class="token punctuation">,</span> <span class="token number">0</span><span class="token punctuation">)</span>
			pdf<span class="token punctuation">.</span><span class="token function">SetTextColor</span><span class="token punctuation">(</span><span class="token number">250</span><span class="token punctuation">,</span> <span class="token number">250</span><span class="token punctuation">,</span> <span class="token number">230</span><span class="token punctuation">)</span>
			pdf<span class="token punctuation">.</span><span class="token function">SetXY</span><span class="token punctuation">(</span>x<span class="token punctuation">,</span> y<span class="token operator">+</span>rectH<span class="token operator">-</span><span class="token number">4</span><span class="token punctuation">)</span>
			pdf<span class="token punctuation">.</span><span class="token function">CellFormat</span><span class="token punctuation">(</span>rectW<span class="token punctuation">,</span> <span class="token number">5</span><span class="token punctuation">,</span> modeList<span class="token punctuation">[</span>j<span class="token punctuation">]</span><span class="token punctuation">,</span> <span class="token string">""</span><span class="token punctuation">,</span> <span class="token number">0</span><span class="token punctuation">,</span> <span class="token string">"C"</span><span class="token punctuation">,</span> <span class="token boolean">true</span><span class="token punctuation">,</span> <span class="token number">0</span><span class="token punctuation">,</span> <span class="token string">""</span><span class="token punctuation">)</span>
			pdf<span class="token punctuation">.</span><span class="token function">SetFont</span><span class="token punctuation">(</span><span class="token string">"Helvetica"</span><span class="token punctuation">,</span> <span class="token string">"I"</span><span class="token punctuation">,</span> <span class="token number">150</span><span class="token punctuation">)</span>
			pdf<span class="token punctuation">.</span><span class="token function">SetTextColor</span><span class="token punctuation">(</span><span class="token number">80</span><span class="token punctuation">,</span> <span class="token number">80</span><span class="token punctuation">,</span> <span class="token number">120</span><span class="token punctuation">)</span>
			pdf<span class="token punctuation">.</span><span class="token function">SetXY</span><span class="token punctuation">(</span>x<span class="token punctuation">,</span> y<span class="token operator">+</span><span class="token number">2</span><span class="token punctuation">)</span>
			pdf<span class="token punctuation">.</span><span class="token function">CellFormat</span><span class="token punctuation">(</span>rectW<span class="token punctuation">,</span> rectH<span class="token punctuation">,</span> <span class="token string">"A"</span><span class="token punctuation">,</span> <span class="token string">""</span><span class="token punctuation">,</span> <span class="token number">0</span><span class="token punctuation">,</span> <span class="token string">"C"</span><span class="token punctuation">,</span> <span class="token boolean">false</span><span class="token punctuation">,</span> <span class="token number">0</span><span class="token punctuation">,</span> <span class="token string">""</span><span class="token punctuation">)</span>
			pdf<span class="token punctuation">.</span><span class="token function">SetAlpha</span><span class="token punctuation">(</span><span class="token number">0.5</span><span class="token punctuation">,</span> modeList<span class="token punctuation">[</span>j<span class="token punctuation">]</span><span class="token punctuation">)</span>
			pdf<span class="token punctuation">.</span><span class="token function">Image</span><span class="token punctuation">(</span>example<span class="token punctuation">.</span><span class="token function">ImageFile</span><span class="token punctuation">(</span><span class="token string">"golang-gopher.png"</span><span class="token punctuation">)</span><span class="token punctuation">,</span>
				x<span class="token operator">-</span>gapX<span class="token punctuation">,</span> y<span class="token punctuation">,</span> rectW<span class="token operator">+</span><span class="token number">2</span><span class="token operator">*</span>gapX<span class="token punctuation">,</span> <span class="token number">0</span><span class="token punctuation">,</span> <span class="token boolean">false</span><span class="token punctuation">,</span> <span class="token string">""</span><span class="token punctuation">,</span> <span class="token number">0</span><span class="token punctuation">,</span> <span class="token string">""</span><span class="token punctuation">)</span>
			pdf<span class="token punctuation">.</span><span class="token function">SetAlpha</span><span class="token punctuation">(</span><span class="token number">1.0</span><span class="token punctuation">,</span> <span class="token string">"Normal"</span><span class="token punctuation">)</span>
			x <span class="token operator">+=</span> rectW <span class="token operator">+</span> gapX
			j<span class="token operator">++</span>
		<span class="token punctuation">&#125;</span>
		y <span class="token operator">+=</span> rectH <span class="token operator">+</span> gapY
	<span class="token punctuation">&#125;</span>
	fileStr <span class="token operator">:=</span> example<span class="token punctuation">.</span><span class="token function">Filename</span><span class="token punctuation">(</span><span class="token string">"Fpdf_SetAlpha_transparency"</span><span class="token punctuation">)</span>
	err <span class="token operator">:=</span> pdf<span class="token punctuation">.</span><span class="token function">OutputFileAndClose</span><span class="token punctuation">(</span>fileStr<span class="token punctuation">)</span>
	example<span class="token punctuation">.</span><span class="token function">Summary</span><span class="token punctuation">(</span>err<span class="token punctuation">,</span> fileStr<span class="token punctuation">)</span>
	<span class="token comment">// Output:</span>
	<span class="token comment">// Successfully generated pdf/Fpdf_SetAlpha_transparency.pdf</span>
<span class="token punctuation">&#125;</span></code></pre>

<h2 id="演示各种梯度"><a href="#演示各种梯度" class="headerlink" title="演示各种梯度"></a>演示各种梯度</h2><pre class="language-go" data-language="go"><code class="language-go"><span class="token comment">// ExampleFpdf_LinearGradient deomstrates various gradients.</span>
<span class="token keyword">func</span> <span class="token function">ExampleFpdf_LinearGradient</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">&#123;</span>
	pdf <span class="token operator">:=</span> gofpdf<span class="token punctuation">.</span><span class="token function">New</span><span class="token punctuation">(</span><span class="token string">""</span><span class="token punctuation">,</span> <span class="token string">""</span><span class="token punctuation">,</span> <span class="token string">""</span><span class="token punctuation">,</span> <span class="token string">""</span><span class="token punctuation">)</span>
	pdf<span class="token punctuation">.</span><span class="token function">SetFont</span><span class="token punctuation">(</span><span class="token string">"Helvetica"</span><span class="token punctuation">,</span> <span class="token string">""</span><span class="token punctuation">,</span> <span class="token number">12</span><span class="token punctuation">)</span>
	pdf<span class="token punctuation">.</span><span class="token function">AddPage</span><span class="token punctuation">(</span><span class="token punctuation">)</span>
	pdf<span class="token punctuation">.</span><span class="token function">LinearGradient</span><span class="token punctuation">(</span><span class="token number">0</span><span class="token punctuation">,</span> <span class="token number">0</span><span class="token punctuation">,</span> <span class="token number">210</span><span class="token punctuation">,</span> <span class="token number">100</span><span class="token punctuation">,</span> <span class="token number">250</span><span class="token punctuation">,</span> <span class="token number">250</span><span class="token punctuation">,</span> <span class="token number">255</span><span class="token punctuation">,</span> <span class="token number">220</span><span class="token punctuation">,</span> <span class="token number">220</span><span class="token punctuation">,</span> <span class="token number">225</span><span class="token punctuation">,</span> <span class="token number">0</span><span class="token punctuation">,</span> <span class="token number">0</span><span class="token punctuation">,</span> <span class="token number">0</span><span class="token punctuation">,</span> <span class="token number">.5</span><span class="token punctuation">)</span>
	pdf<span class="token punctuation">.</span><span class="token function">LinearGradient</span><span class="token punctuation">(</span><span class="token number">20</span><span class="token punctuation">,</span> <span class="token number">25</span><span class="token punctuation">,</span> <span class="token number">75</span><span class="token punctuation">,</span> <span class="token number">75</span><span class="token punctuation">,</span> <span class="token number">220</span><span class="token punctuation">,</span> <span class="token number">220</span><span class="token punctuation">,</span> <span class="token number">250</span><span class="token punctuation">,</span> <span class="token number">80</span><span class="token punctuation">,</span> <span class="token number">80</span><span class="token punctuation">,</span> <span class="token number">220</span><span class="token punctuation">,</span> <span class="token number">0</span><span class="token punctuation">,</span> <span class="token number">.2</span><span class="token punctuation">,</span> <span class="token number">0</span><span class="token punctuation">,</span> <span class="token number">.8</span><span class="token punctuation">)</span>
	pdf<span class="token punctuation">.</span><span class="token function">Rect</span><span class="token punctuation">(</span><span class="token number">20</span><span class="token punctuation">,</span> <span class="token number">25</span><span class="token punctuation">,</span> <span class="token number">75</span><span class="token punctuation">,</span> <span class="token number">75</span><span class="token punctuation">,</span> <span class="token string">"D"</span><span class="token punctuation">)</span>
	pdf<span class="token punctuation">.</span><span class="token function">LinearGradient</span><span class="token punctuation">(</span><span class="token number">115</span><span class="token punctuation">,</span> <span class="token number">25</span><span class="token punctuation">,</span> <span class="token number">75</span><span class="token punctuation">,</span> <span class="token number">75</span><span class="token punctuation">,</span> <span class="token number">220</span><span class="token punctuation">,</span> <span class="token number">220</span><span class="token punctuation">,</span> <span class="token number">250</span><span class="token punctuation">,</span> <span class="token number">80</span><span class="token punctuation">,</span> <span class="token number">80</span><span class="token punctuation">,</span> <span class="token number">220</span><span class="token punctuation">,</span> <span class="token number">0</span><span class="token punctuation">,</span> <span class="token number">0</span><span class="token punctuation">,</span> <span class="token number">1</span><span class="token punctuation">,</span> <span class="token number">1</span><span class="token punctuation">)</span>
	pdf<span class="token punctuation">.</span><span class="token function">Rect</span><span class="token punctuation">(</span><span class="token number">115</span><span class="token punctuation">,</span> <span class="token number">25</span><span class="token punctuation">,</span> <span class="token number">75</span><span class="token punctuation">,</span> <span class="token number">75</span><span class="token punctuation">,</span> <span class="token string">"D"</span><span class="token punctuation">)</span>
	pdf<span class="token punctuation">.</span><span class="token function">RadialGradient</span><span class="token punctuation">(</span><span class="token number">20</span><span class="token punctuation">,</span> <span class="token number">120</span><span class="token punctuation">,</span> <span class="token number">75</span><span class="token punctuation">,</span> <span class="token number">75</span><span class="token punctuation">,</span> <span class="token number">220</span><span class="token punctuation">,</span> <span class="token number">220</span><span class="token punctuation">,</span> <span class="token number">250</span><span class="token punctuation">,</span> <span class="token number">80</span><span class="token punctuation">,</span> <span class="token number">80</span><span class="token punctuation">,</span> <span class="token number">220</span><span class="token punctuation">,</span>
		<span class="token number">0.25</span><span class="token punctuation">,</span> <span class="token number">0.75</span><span class="token punctuation">,</span> <span class="token number">0.25</span><span class="token punctuation">,</span> <span class="token number">0.75</span><span class="token punctuation">,</span> <span class="token number">1</span><span class="token punctuation">)</span>
	pdf<span class="token punctuation">.</span><span class="token function">Rect</span><span class="token punctuation">(</span><span class="token number">20</span><span class="token punctuation">,</span> <span class="token number">120</span><span class="token punctuation">,</span> <span class="token number">75</span><span class="token punctuation">,</span> <span class="token number">75</span><span class="token punctuation">,</span> <span class="token string">"D"</span><span class="token punctuation">)</span>
	pdf<span class="token punctuation">.</span><span class="token function">RadialGradient</span><span class="token punctuation">(</span><span class="token number">115</span><span class="token punctuation">,</span> <span class="token number">120</span><span class="token punctuation">,</span> <span class="token number">75</span><span class="token punctuation">,</span> <span class="token number">75</span><span class="token punctuation">,</span> <span class="token number">220</span><span class="token punctuation">,</span> <span class="token number">220</span><span class="token punctuation">,</span> <span class="token number">250</span><span class="token punctuation">,</span> <span class="token number">80</span><span class="token punctuation">,</span> <span class="token number">80</span><span class="token punctuation">,</span> <span class="token number">220</span><span class="token punctuation">,</span>
		<span class="token number">0.25</span><span class="token punctuation">,</span> <span class="token number">0.75</span><span class="token punctuation">,</span> <span class="token number">0.75</span><span class="token punctuation">,</span> <span class="token number">0.75</span><span class="token punctuation">,</span> <span class="token number">0.75</span><span class="token punctuation">)</span>
	pdf<span class="token punctuation">.</span><span class="token function">Rect</span><span class="token punctuation">(</span><span class="token number">115</span><span class="token punctuation">,</span> <span class="token number">120</span><span class="token punctuation">,</span> <span class="token number">75</span><span class="token punctuation">,</span> <span class="token number">75</span><span class="token punctuation">,</span> <span class="token string">"D"</span><span class="token punctuation">)</span>
	fileStr <span class="token operator">:=</span> example<span class="token punctuation">.</span><span class="token function">Filename</span><span class="token punctuation">(</span><span class="token string">"Fpdf_LinearGradient_gradient"</span><span class="token punctuation">)</span>
	err <span class="token operator">:=</span> pdf<span class="token punctuation">.</span><span class="token function">OutputFileAndClose</span><span class="token punctuation">(</span>fileStr<span class="token punctuation">)</span>
	example<span class="token punctuation">.</span><span class="token function">Summary</span><span class="token punctuation">(</span>err<span class="token punctuation">,</span> fileStr<span class="token punctuation">)</span>
	<span class="token comment">// Output:</span>
	<span class="token comment">// Successfully generated pdf/Fpdf_LinearGradient_gradient.pdf</span>
<span class="token punctuation">&#125;</span></code></pre>

<h2 id="演示了剪裁"><a href="#演示了剪裁" class="headerlink" title="演示了剪裁"></a>演示了剪裁</h2><pre class="language-go" data-language="go"><code class="language-go"><span class="token comment">// ExampleFpdf_ClipText demonstrates clipping.</span>
<span class="token keyword">func</span> <span class="token function">ExampleFpdf_ClipText</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">&#123;</span>
	pdf <span class="token operator">:=</span> gofpdf<span class="token punctuation">.</span><span class="token function">New</span><span class="token punctuation">(</span><span class="token string">""</span><span class="token punctuation">,</span> <span class="token string">""</span><span class="token punctuation">,</span> <span class="token string">""</span><span class="token punctuation">,</span> <span class="token string">""</span><span class="token punctuation">)</span>
	y <span class="token operator">:=</span> <span class="token number">10.0</span>
	pdf<span class="token punctuation">.</span><span class="token function">AddPage</span><span class="token punctuation">(</span><span class="token punctuation">)</span>

	pdf<span class="token punctuation">.</span><span class="token function">SetFont</span><span class="token punctuation">(</span><span class="token string">"Helvetica"</span><span class="token punctuation">,</span> <span class="token string">""</span><span class="token punctuation">,</span> <span class="token number">24</span><span class="token punctuation">)</span>
	pdf<span class="token punctuation">.</span><span class="token function">SetXY</span><span class="token punctuation">(</span><span class="token number">0</span><span class="token punctuation">,</span> y<span class="token punctuation">)</span>
	pdf<span class="token punctuation">.</span><span class="token function">ClipText</span><span class="token punctuation">(</span><span class="token number">10</span><span class="token punctuation">,</span> y<span class="token operator">+</span><span class="token number">12</span><span class="token punctuation">,</span> <span class="token string">"Clipping examples"</span><span class="token punctuation">,</span> <span class="token boolean">false</span><span class="token punctuation">)</span>
	pdf<span class="token punctuation">.</span><span class="token function">RadialGradient</span><span class="token punctuation">(</span><span class="token number">10</span><span class="token punctuation">,</span> y<span class="token punctuation">,</span> <span class="token number">100</span><span class="token punctuation">,</span> <span class="token number">20</span><span class="token punctuation">,</span> <span class="token number">128</span><span class="token punctuation">,</span> <span class="token number">128</span><span class="token punctuation">,</span> <span class="token number">160</span><span class="token punctuation">,</span> <span class="token number">32</span><span class="token punctuation">,</span> <span class="token number">32</span><span class="token punctuation">,</span> <span class="token number">48</span><span class="token punctuation">,</span>
		<span class="token number">0.25</span><span class="token punctuation">,</span> <span class="token number">0.5</span><span class="token punctuation">,</span> <span class="token number">0.25</span><span class="token punctuation">,</span> <span class="token number">0.5</span><span class="token punctuation">,</span> <span class="token number">0.2</span><span class="token punctuation">)</span>
	pdf<span class="token punctuation">.</span><span class="token function">ClipEnd</span><span class="token punctuation">(</span><span class="token punctuation">)</span>

	y <span class="token operator">+=</span> <span class="token number">12</span>
	pdf<span class="token punctuation">.</span><span class="token function">SetFont</span><span class="token punctuation">(</span><span class="token string">"Helvetica"</span><span class="token punctuation">,</span> <span class="token string">"B"</span><span class="token punctuation">,</span> <span class="token number">120</span><span class="token punctuation">)</span>
	pdf<span class="token punctuation">.</span><span class="token function">SetDrawColor</span><span class="token punctuation">(</span><span class="token number">64</span><span class="token punctuation">,</span> <span class="token number">80</span><span class="token punctuation">,</span> <span class="token number">80</span><span class="token punctuation">)</span>
	pdf<span class="token punctuation">.</span><span class="token function">SetLineWidth</span><span class="token punctuation">(</span><span class="token number">.5</span><span class="token punctuation">)</span>
	pdf<span class="token punctuation">.</span><span class="token function">ClipText</span><span class="token punctuation">(</span><span class="token number">10</span><span class="token punctuation">,</span> y<span class="token operator">+</span><span class="token number">40</span><span class="token punctuation">,</span> pdf<span class="token punctuation">.</span><span class="token function">String</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">,</span> <span class="token boolean">true</span><span class="token punctuation">)</span>
	pdf<span class="token punctuation">.</span><span class="token function">RadialGradient</span><span class="token punctuation">(</span><span class="token number">10</span><span class="token punctuation">,</span> y<span class="token punctuation">,</span> <span class="token number">200</span><span class="token punctuation">,</span> <span class="token number">50</span><span class="token punctuation">,</span> <span class="token number">220</span><span class="token punctuation">,</span> <span class="token number">220</span><span class="token punctuation">,</span> <span class="token number">250</span><span class="token punctuation">,</span> <span class="token number">80</span><span class="token punctuation">,</span> <span class="token number">80</span><span class="token punctuation">,</span> <span class="token number">220</span><span class="token punctuation">,</span>
		<span class="token number">0.25</span><span class="token punctuation">,</span> <span class="token number">0.5</span><span class="token punctuation">,</span> <span class="token number">0.25</span><span class="token punctuation">,</span> <span class="token number">0.5</span><span class="token punctuation">,</span> <span class="token number">1</span><span class="token punctuation">)</span>
	pdf<span class="token punctuation">.</span><span class="token function">ClipEnd</span><span class="token punctuation">(</span><span class="token punctuation">)</span>

	y <span class="token operator">+=</span> <span class="token number">55</span>
	pdf<span class="token punctuation">.</span><span class="token function">ClipRect</span><span class="token punctuation">(</span><span class="token number">10</span><span class="token punctuation">,</span> y<span class="token punctuation">,</span> <span class="token number">105</span><span class="token punctuation">,</span> <span class="token number">20</span><span class="token punctuation">,</span> <span class="token boolean">true</span><span class="token punctuation">)</span>
	pdf<span class="token punctuation">.</span><span class="token function">SetFillColor</span><span class="token punctuation">(</span><span class="token number">255</span><span class="token punctuation">,</span> <span class="token number">255</span><span class="token punctuation">,</span> <span class="token number">255</span><span class="token punctuation">)</span>
	pdf<span class="token punctuation">.</span><span class="token function">Rect</span><span class="token punctuation">(</span><span class="token number">10</span><span class="token punctuation">,</span> y<span class="token punctuation">,</span> <span class="token number">105</span><span class="token punctuation">,</span> <span class="token number">20</span><span class="token punctuation">,</span> <span class="token string">"F"</span><span class="token punctuation">)</span>
	pdf<span class="token punctuation">.</span><span class="token function">ClipCircle</span><span class="token punctuation">(</span><span class="token number">40</span><span class="token punctuation">,</span> y<span class="token operator">+</span><span class="token number">10</span><span class="token punctuation">,</span> <span class="token number">15</span><span class="token punctuation">,</span> <span class="token boolean">false</span><span class="token punctuation">)</span>
	pdf<span class="token punctuation">.</span><span class="token function">RadialGradient</span><span class="token punctuation">(</span><span class="token number">25</span><span class="token punctuation">,</span> y<span class="token punctuation">,</span> <span class="token number">30</span><span class="token punctuation">,</span> <span class="token number">30</span><span class="token punctuation">,</span> <span class="token number">220</span><span class="token punctuation">,</span> <span class="token number">250</span><span class="token punctuation">,</span> <span class="token number">220</span><span class="token punctuation">,</span> <span class="token number">40</span><span class="token punctuation">,</span> <span class="token number">60</span><span class="token punctuation">,</span> <span class="token number">40</span><span class="token punctuation">,</span> <span class="token number">0.3</span><span class="token punctuation">,</span>
		<span class="token number">0.85</span><span class="token punctuation">,</span> <span class="token number">0.3</span><span class="token punctuation">,</span> <span class="token number">0.85</span><span class="token punctuation">,</span> <span class="token number">0.5</span><span class="token punctuation">)</span>
	pdf<span class="token punctuation">.</span><span class="token function">ClipEnd</span><span class="token punctuation">(</span><span class="token punctuation">)</span>
	pdf<span class="token punctuation">.</span><span class="token function">ClipEllipse</span><span class="token punctuation">(</span><span class="token number">80</span><span class="token punctuation">,</span> y<span class="token operator">+</span><span class="token number">10</span><span class="token punctuation">,</span> <span class="token number">20</span><span class="token punctuation">,</span> <span class="token number">15</span><span class="token punctuation">,</span> <span class="token boolean">false</span><span class="token punctuation">)</span>
	pdf<span class="token punctuation">.</span><span class="token function">RadialGradient</span><span class="token punctuation">(</span><span class="token number">60</span><span class="token punctuation">,</span> y<span class="token punctuation">,</span> <span class="token number">40</span><span class="token punctuation">,</span> <span class="token number">30</span><span class="token punctuation">,</span> <span class="token number">250</span><span class="token punctuation">,</span> <span class="token number">220</span><span class="token punctuation">,</span> <span class="token number">220</span><span class="token punctuation">,</span> <span class="token number">60</span><span class="token punctuation">,</span> <span class="token number">40</span><span class="token punctuation">,</span> <span class="token number">40</span><span class="token punctuation">,</span> <span class="token number">0.3</span><span class="token punctuation">,</span>
		<span class="token number">0.85</span><span class="token punctuation">,</span> <span class="token number">0.3</span><span class="token punctuation">,</span> <span class="token number">0.85</span><span class="token punctuation">,</span> <span class="token number">0.5</span><span class="token punctuation">)</span>
	pdf<span class="token punctuation">.</span><span class="token function">ClipEnd</span><span class="token punctuation">(</span><span class="token punctuation">)</span>
	pdf<span class="token punctuation">.</span><span class="token function">ClipEnd</span><span class="token punctuation">(</span><span class="token punctuation">)</span>

	y <span class="token operator">+=</span> <span class="token number">28</span>
	pdf<span class="token punctuation">.</span><span class="token function">ClipEllipse</span><span class="token punctuation">(</span><span class="token number">26</span><span class="token punctuation">,</span> y<span class="token operator">+</span><span class="token number">10</span><span class="token punctuation">,</span> <span class="token number">16</span><span class="token punctuation">,</span> <span class="token number">10</span><span class="token punctuation">,</span> <span class="token boolean">true</span><span class="token punctuation">)</span>
	pdf<span class="token punctuation">.</span><span class="token function">Image</span><span class="token punctuation">(</span>example<span class="token punctuation">.</span><span class="token function">ImageFile</span><span class="token punctuation">(</span><span class="token string">"logo.jpg"</span><span class="token punctuation">)</span><span class="token punctuation">,</span> <span class="token number">10</span><span class="token punctuation">,</span> y<span class="token punctuation">,</span> <span class="token number">32</span><span class="token punctuation">,</span> <span class="token number">0</span><span class="token punctuation">,</span> <span class="token boolean">false</span><span class="token punctuation">,</span> <span class="token string">"JPG"</span><span class="token punctuation">,</span> <span class="token number">0</span><span class="token punctuation">,</span> <span class="token string">""</span><span class="token punctuation">)</span>
	pdf<span class="token punctuation">.</span><span class="token function">ClipEnd</span><span class="token punctuation">(</span><span class="token punctuation">)</span>

	pdf<span class="token punctuation">.</span><span class="token function">ClipCircle</span><span class="token punctuation">(</span><span class="token number">60</span><span class="token punctuation">,</span> y<span class="token operator">+</span><span class="token number">10</span><span class="token punctuation">,</span> <span class="token number">10</span><span class="token punctuation">,</span> <span class="token boolean">true</span><span class="token punctuation">)</span>
	pdf<span class="token punctuation">.</span><span class="token function">RadialGradient</span><span class="token punctuation">(</span><span class="token number">50</span><span class="token punctuation">,</span> y<span class="token punctuation">,</span> <span class="token number">20</span><span class="token punctuation">,</span> <span class="token number">20</span><span class="token punctuation">,</span> <span class="token number">220</span><span class="token punctuation">,</span> <span class="token number">220</span><span class="token punctuation">,</span> <span class="token number">250</span><span class="token punctuation">,</span> <span class="token number">40</span><span class="token punctuation">,</span> <span class="token number">40</span><span class="token punctuation">,</span> <span class="token number">60</span><span class="token punctuation">,</span> <span class="token number">0.3</span><span class="token punctuation">,</span>
		<span class="token number">0.7</span><span class="token punctuation">,</span> <span class="token number">0.3</span><span class="token punctuation">,</span> <span class="token number">0.7</span><span class="token punctuation">,</span> <span class="token number">0.5</span><span class="token punctuation">)</span>
	pdf<span class="token punctuation">.</span><span class="token function">ClipEnd</span><span class="token punctuation">(</span><span class="token punctuation">)</span>

	pdf<span class="token punctuation">.</span><span class="token function">ClipPolygon</span><span class="token punctuation">(</span><span class="token punctuation">[</span><span class="token punctuation">]</span>gofpdf<span class="token punctuation">.</span>PointType<span class="token punctuation">&#123;</span><span class="token punctuation">&#123;</span>X<span class="token punctuation">:</span> <span class="token number">80</span><span class="token punctuation">,</span> Y<span class="token punctuation">:</span> y <span class="token operator">+</span> <span class="token number">20</span><span class="token punctuation">&#125;</span><span class="token punctuation">,</span> <span class="token punctuation">&#123;</span>X<span class="token punctuation">:</span> <span class="token number">90</span><span class="token punctuation">,</span> Y<span class="token punctuation">:</span> y<span class="token punctuation">&#125;</span><span class="token punctuation">,</span>
		<span class="token punctuation">&#123;</span>X<span class="token punctuation">:</span> <span class="token number">100</span><span class="token punctuation">,</span> Y<span class="token punctuation">:</span> y <span class="token operator">+</span> <span class="token number">20</span><span class="token punctuation">&#125;</span><span class="token punctuation">&#125;</span><span class="token punctuation">,</span> <span class="token boolean">true</span><span class="token punctuation">)</span>
	pdf<span class="token punctuation">.</span><span class="token function">LinearGradient</span><span class="token punctuation">(</span><span class="token number">80</span><span class="token punctuation">,</span> y<span class="token punctuation">,</span> <span class="token number">20</span><span class="token punctuation">,</span> <span class="token number">20</span><span class="token punctuation">,</span> <span class="token number">250</span><span class="token punctuation">,</span> <span class="token number">220</span><span class="token punctuation">,</span> <span class="token number">250</span><span class="token punctuation">,</span> <span class="token number">60</span><span class="token punctuation">,</span> <span class="token number">40</span><span class="token punctuation">,</span> <span class="token number">60</span><span class="token punctuation">,</span> <span class="token number">0.5</span><span class="token punctuation">,</span>
		<span class="token number">1</span><span class="token punctuation">,</span> <span class="token number">0.5</span><span class="token punctuation">,</span> <span class="token number">0.5</span><span class="token punctuation">)</span>
	pdf<span class="token punctuation">.</span><span class="token function">ClipEnd</span><span class="token punctuation">(</span><span class="token punctuation">)</span>

	y <span class="token operator">+=</span> <span class="token number">30</span>
	pdf<span class="token punctuation">.</span><span class="token function">SetLineWidth</span><span class="token punctuation">(</span><span class="token number">.1</span><span class="token punctuation">)</span>
	pdf<span class="token punctuation">.</span><span class="token function">SetDrawColor</span><span class="token punctuation">(</span><span class="token number">180</span><span class="token punctuation">,</span> <span class="token number">180</span><span class="token punctuation">,</span> <span class="token number">180</span><span class="token punctuation">)</span>
	pdf<span class="token punctuation">.</span><span class="token function">ClipRoundedRect</span><span class="token punctuation">(</span><span class="token number">10</span><span class="token punctuation">,</span> y<span class="token punctuation">,</span> <span class="token number">120</span><span class="token punctuation">,</span> <span class="token number">20</span><span class="token punctuation">,</span> <span class="token number">5</span><span class="token punctuation">,</span> <span class="token boolean">true</span><span class="token punctuation">)</span>
	pdf<span class="token punctuation">.</span><span class="token function">RadialGradient</span><span class="token punctuation">(</span><span class="token number">10</span><span class="token punctuation">,</span> y<span class="token punctuation">,</span> <span class="token number">120</span><span class="token punctuation">,</span> <span class="token number">20</span><span class="token punctuation">,</span> <span class="token number">255</span><span class="token punctuation">,</span> <span class="token number">255</span><span class="token punctuation">,</span> <span class="token number">255</span><span class="token punctuation">,</span> <span class="token number">240</span><span class="token punctuation">,</span> <span class="token number">240</span><span class="token punctuation">,</span> <span class="token number">220</span><span class="token punctuation">,</span>
		<span class="token number">0.25</span><span class="token punctuation">,</span> <span class="token number">0.75</span><span class="token punctuation">,</span> <span class="token number">0.25</span><span class="token punctuation">,</span> <span class="token number">0.75</span><span class="token punctuation">,</span> <span class="token number">0.5</span><span class="token punctuation">)</span>
	pdf<span class="token punctuation">.</span><span class="token function">SetXY</span><span class="token punctuation">(</span><span class="token number">5</span><span class="token punctuation">,</span> y<span class="token operator">-</span><span class="token number">5</span><span class="token punctuation">)</span>
	pdf<span class="token punctuation">.</span><span class="token function">SetFont</span><span class="token punctuation">(</span><span class="token string">"Times"</span><span class="token punctuation">,</span> <span class="token string">""</span><span class="token punctuation">,</span> <span class="token number">12</span><span class="token punctuation">)</span>
	pdf<span class="token punctuation">.</span><span class="token function">MultiCell</span><span class="token punctuation">(</span><span class="token number">130</span><span class="token punctuation">,</span> <span class="token number">5</span><span class="token punctuation">,</span> <span class="token function">lorem</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">,</span> <span class="token string">""</span><span class="token punctuation">,</span> <span class="token string">""</span><span class="token punctuation">,</span> <span class="token boolean">false</span><span class="token punctuation">)</span>
	pdf<span class="token punctuation">.</span><span class="token function">ClipEnd</span><span class="token punctuation">(</span><span class="token punctuation">)</span>

	y <span class="token operator">+=</span> <span class="token number">30</span>
	pdf<span class="token punctuation">.</span><span class="token function">SetDrawColor</span><span class="token punctuation">(</span><span class="token number">180</span><span class="token punctuation">,</span> <span class="token number">100</span><span class="token punctuation">,</span> <span class="token number">180</span><span class="token punctuation">)</span>
	pdf<span class="token punctuation">.</span><span class="token function">ClipRoundedRectExt</span><span class="token punctuation">(</span><span class="token number">10</span><span class="token punctuation">,</span> y<span class="token punctuation">,</span> <span class="token number">120</span><span class="token punctuation">,</span> <span class="token number">20</span><span class="token punctuation">,</span> <span class="token number">5</span><span class="token punctuation">,</span> <span class="token number">10</span><span class="token punctuation">,</span> <span class="token number">5</span><span class="token punctuation">,</span> <span class="token number">10</span><span class="token punctuation">,</span> <span class="token boolean">true</span><span class="token punctuation">)</span>
	pdf<span class="token punctuation">.</span><span class="token function">RadialGradient</span><span class="token punctuation">(</span><span class="token number">10</span><span class="token punctuation">,</span> y<span class="token punctuation">,</span> <span class="token number">120</span><span class="token punctuation">,</span> <span class="token number">20</span><span class="token punctuation">,</span> <span class="token number">255</span><span class="token punctuation">,</span> <span class="token number">255</span><span class="token punctuation">,</span> <span class="token number">255</span><span class="token punctuation">,</span> <span class="token number">240</span><span class="token punctuation">,</span> <span class="token number">240</span><span class="token punctuation">,</span> <span class="token number">220</span><span class="token punctuation">,</span>
		<span class="token number">0.25</span><span class="token punctuation">,</span> <span class="token number">0.75</span><span class="token punctuation">,</span> <span class="token number">0.25</span><span class="token punctuation">,</span> <span class="token number">0.75</span><span class="token punctuation">,</span> <span class="token number">0.5</span><span class="token punctuation">)</span>
	pdf<span class="token punctuation">.</span><span class="token function">SetXY</span><span class="token punctuation">(</span><span class="token number">5</span><span class="token punctuation">,</span> y<span class="token operator">-</span><span class="token number">5</span><span class="token punctuation">)</span>
	pdf<span class="token punctuation">.</span><span class="token function">SetFont</span><span class="token punctuation">(</span><span class="token string">"Times"</span><span class="token punctuation">,</span> <span class="token string">""</span><span class="token punctuation">,</span> <span class="token number">12</span><span class="token punctuation">)</span>
	pdf<span class="token punctuation">.</span><span class="token function">MultiCell</span><span class="token punctuation">(</span><span class="token number">130</span><span class="token punctuation">,</span> <span class="token number">5</span><span class="token punctuation">,</span> <span class="token function">lorem</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">,</span> <span class="token string">""</span><span class="token punctuation">,</span> <span class="token string">""</span><span class="token punctuation">,</span> <span class="token boolean">false</span><span class="token punctuation">)</span>
	pdf<span class="token punctuation">.</span><span class="token function">ClipEnd</span><span class="token punctuation">(</span><span class="token punctuation">)</span>

	fileStr <span class="token operator">:=</span> example<span class="token punctuation">.</span><span class="token function">Filename</span><span class="token punctuation">(</span><span class="token string">"Fpdf_ClipText"</span><span class="token punctuation">)</span>
	err <span class="token operator">:=</span> pdf<span class="token punctuation">.</span><span class="token function">OutputFileAndClose</span><span class="token punctuation">(</span>fileStr<span class="token punctuation">)</span>
	example<span class="token punctuation">.</span><span class="token function">Summary</span><span class="token punctuation">(</span>err<span class="token punctuation">,</span> fileStr<span class="token punctuation">)</span>
	<span class="token comment">// Output:</span>
	<span class="token comment">// Successfully generated pdf/Fpdf_ClipText.pdf</span>
<span class="token punctuation">&#125;</span></code></pre>

<h2 id="生成具有不同页面大小的PDF文档"><a href="#生成具有不同页面大小的PDF文档" class="headerlink" title="生成具有不同页面大小的PDF文档"></a>生成具有不同页面大小的PDF文档</h2><pre class="language-go" data-language="go"><code class="language-go"><span class="token comment">// ExampleFpdf_PageSize generates a PDF document with various page sizes.</span>
<span class="token keyword">func</span> <span class="token function">ExampleFpdf_PageSize</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">&#123;</span>
	pdf <span class="token operator">:=</span> gofpdf<span class="token punctuation">.</span><span class="token function">NewCustom</span><span class="token punctuation">(</span><span class="token operator">&amp;</span>gofpdf<span class="token punctuation">.</span>InitType<span class="token punctuation">&#123;</span>
		UnitStr<span class="token punctuation">:</span>    <span class="token string">"in"</span><span class="token punctuation">,</span>
		Size<span class="token punctuation">:</span>       gofpdf<span class="token punctuation">.</span>SizeType<span class="token punctuation">&#123;</span>Wd<span class="token punctuation">:</span> <span class="token number">6</span><span class="token punctuation">,</span> Ht<span class="token punctuation">:</span> <span class="token number">6</span><span class="token punctuation">&#125;</span><span class="token punctuation">,</span>
		FontDirStr<span class="token punctuation">:</span> example<span class="token punctuation">.</span><span class="token function">FontDir</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">,</span>
	<span class="token punctuation">&#125;</span><span class="token punctuation">)</span>
	pdf<span class="token punctuation">.</span><span class="token function">SetMargins</span><span class="token punctuation">(</span><span class="token number">0.5</span><span class="token punctuation">,</span> <span class="token number">1</span><span class="token punctuation">,</span> <span class="token number">0.5</span><span class="token punctuation">)</span>
	pdf<span class="token punctuation">.</span><span class="token function">SetFont</span><span class="token punctuation">(</span><span class="token string">"Times"</span><span class="token punctuation">,</span> <span class="token string">""</span><span class="token punctuation">,</span> <span class="token number">14</span><span class="token punctuation">)</span>
	pdf<span class="token punctuation">.</span><span class="token function">AddPageFormat</span><span class="token punctuation">(</span><span class="token string">"L"</span><span class="token punctuation">,</span> gofpdf<span class="token punctuation">.</span>SizeType<span class="token punctuation">&#123;</span>Wd<span class="token punctuation">:</span> <span class="token number">3</span><span class="token punctuation">,</span> Ht<span class="token punctuation">:</span> <span class="token number">12</span><span class="token punctuation">&#125;</span><span class="token punctuation">)</span>
	pdf<span class="token punctuation">.</span><span class="token function">SetXY</span><span class="token punctuation">(</span><span class="token number">0.5</span><span class="token punctuation">,</span> <span class="token number">1.5</span><span class="token punctuation">)</span>
	pdf<span class="token punctuation">.</span><span class="token function">CellFormat</span><span class="token punctuation">(</span><span class="token number">11</span><span class="token punctuation">,</span> <span class="token number">0.2</span><span class="token punctuation">,</span> <span class="token string">"12 in x 3 in"</span><span class="token punctuation">,</span> <span class="token string">""</span><span class="token punctuation">,</span> <span class="token number">0</span><span class="token punctuation">,</span> <span class="token string">"C"</span><span class="token punctuation">,</span> <span class="token boolean">false</span><span class="token punctuation">,</span> <span class="token number">0</span><span class="token punctuation">,</span> <span class="token string">""</span><span class="token punctuation">)</span>
	pdf<span class="token punctuation">.</span><span class="token function">AddPage</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token comment">// Default size established in NewCustom()</span>
	pdf<span class="token punctuation">.</span><span class="token function">SetXY</span><span class="token punctuation">(</span><span class="token number">0.5</span><span class="token punctuation">,</span> <span class="token number">3</span><span class="token punctuation">)</span>
	pdf<span class="token punctuation">.</span><span class="token function">CellFormat</span><span class="token punctuation">(</span><span class="token number">5</span><span class="token punctuation">,</span> <span class="token number">0.2</span><span class="token punctuation">,</span> <span class="token string">"6 in x 6 in"</span><span class="token punctuation">,</span> <span class="token string">""</span><span class="token punctuation">,</span> <span class="token number">0</span><span class="token punctuation">,</span> <span class="token string">"C"</span><span class="token punctuation">,</span> <span class="token boolean">false</span><span class="token punctuation">,</span> <span class="token number">0</span><span class="token punctuation">,</span> <span class="token string">""</span><span class="token punctuation">)</span>
	pdf<span class="token punctuation">.</span><span class="token function">AddPageFormat</span><span class="token punctuation">(</span><span class="token string">"P"</span><span class="token punctuation">,</span> gofpdf<span class="token punctuation">.</span>SizeType<span class="token punctuation">&#123;</span>Wd<span class="token punctuation">:</span> <span class="token number">3</span><span class="token punctuation">,</span> Ht<span class="token punctuation">:</span> <span class="token number">12</span><span class="token punctuation">&#125;</span><span class="token punctuation">)</span>
	pdf<span class="token punctuation">.</span><span class="token function">SetXY</span><span class="token punctuation">(</span><span class="token number">0.5</span><span class="token punctuation">,</span> <span class="token number">6</span><span class="token punctuation">)</span>
	pdf<span class="token punctuation">.</span><span class="token function">CellFormat</span><span class="token punctuation">(</span><span class="token number">2</span><span class="token punctuation">,</span> <span class="token number">0.2</span><span class="token punctuation">,</span> <span class="token string">"3 in x 12 in"</span><span class="token punctuation">,</span> <span class="token string">""</span><span class="token punctuation">,</span> <span class="token number">0</span><span class="token punctuation">,</span> <span class="token string">"C"</span><span class="token punctuation">,</span> <span class="token boolean">false</span><span class="token punctuation">,</span> <span class="token number">0</span><span class="token punctuation">,</span> <span class="token string">""</span><span class="token punctuation">)</span>
	<span class="token keyword">for</span> j <span class="token operator">:=</span> <span class="token number">0</span><span class="token punctuation">;</span> j <span class="token operator">&lt;=</span> <span class="token number">3</span><span class="token punctuation">;</span> j<span class="token operator">++</span> <span class="token punctuation">&#123;</span>
		wd<span class="token punctuation">,</span> ht<span class="token punctuation">,</span> u <span class="token operator">:=</span> pdf<span class="token punctuation">.</span><span class="token function">PageSize</span><span class="token punctuation">(</span>j<span class="token punctuation">)</span>
		fmt<span class="token punctuation">.</span><span class="token function">Printf</span><span class="token punctuation">(</span><span class="token string">"%d: %6.2f %s, %6.2f %s\n"</span><span class="token punctuation">,</span> j<span class="token punctuation">,</span> wd<span class="token punctuation">,</span> u<span class="token punctuation">,</span> ht<span class="token punctuation">,</span> u<span class="token punctuation">)</span>
	<span class="token punctuation">&#125;</span>
	fileStr <span class="token operator">:=</span> example<span class="token punctuation">.</span><span class="token function">Filename</span><span class="token punctuation">(</span><span class="token string">"Fpdf_PageSize"</span><span class="token punctuation">)</span>
	err <span class="token operator">:=</span> pdf<span class="token punctuation">.</span><span class="token function">OutputFileAndClose</span><span class="token punctuation">(</span>fileStr<span class="token punctuation">)</span>
	example<span class="token punctuation">.</span><span class="token function">Summary</span><span class="token punctuation">(</span>err<span class="token punctuation">,</span> fileStr<span class="token punctuation">)</span>
	<span class="token comment">// Output:</span>
	<span class="token comment">// 0:   6.00 in,   6.00 in</span>
	<span class="token comment">// 1:  12.00 in,   3.00 in</span>
	<span class="token comment">// 2:   6.00 in,   6.00 in</span>
	<span class="token comment">// 3:   3.00 in,  12.00 in</span>
	<span class="token comment">// Successfully generated pdf/Fpdf_PageSize.pdf</span>
<span class="token punctuation">&#125;</span></code></pre>

<h2 id="演示Bookmark方法"><a href="#演示Bookmark方法" class="headerlink" title="演示Bookmark方法"></a>演示Bookmark方法</h2><pre class="language-go" data-language="go"><code class="language-go"><span class="token comment">// ExampleFpdf_Bookmark demonstrates the Bookmark method.</span>
<span class="token keyword">func</span> <span class="token function">ExampleFpdf_Bookmark</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">&#123;</span>
	pdf <span class="token operator">:=</span> gofpdf<span class="token punctuation">.</span><span class="token function">New</span><span class="token punctuation">(</span><span class="token string">"P"</span><span class="token punctuation">,</span> <span class="token string">"mm"</span><span class="token punctuation">,</span> <span class="token string">"A4"</span><span class="token punctuation">,</span> <span class="token string">""</span><span class="token punctuation">)</span>
	pdf<span class="token punctuation">.</span><span class="token function">AddPage</span><span class="token punctuation">(</span><span class="token punctuation">)</span>
	pdf<span class="token punctuation">.</span><span class="token function">SetFont</span><span class="token punctuation">(</span><span class="token string">"Arial"</span><span class="token punctuation">,</span> <span class="token string">""</span><span class="token punctuation">,</span> <span class="token number">15</span><span class="token punctuation">)</span>
	pdf<span class="token punctuation">.</span><span class="token function">Bookmark</span><span class="token punctuation">(</span><span class="token string">"Page 1"</span><span class="token punctuation">,</span> <span class="token number">0</span><span class="token punctuation">,</span> <span class="token number">0</span><span class="token punctuation">)</span>
	pdf<span class="token punctuation">.</span><span class="token function">Bookmark</span><span class="token punctuation">(</span><span class="token string">"Paragraph 1"</span><span class="token punctuation">,</span> <span class="token number">1</span><span class="token punctuation">,</span> <span class="token operator">-</span><span class="token number">1</span><span class="token punctuation">)</span>
	pdf<span class="token punctuation">.</span><span class="token function">Cell</span><span class="token punctuation">(</span><span class="token number">0</span><span class="token punctuation">,</span> <span class="token number">6</span><span class="token punctuation">,</span> <span class="token string">"Paragraph 1"</span><span class="token punctuation">)</span>
	pdf<span class="token punctuation">.</span><span class="token function">Ln</span><span class="token punctuation">(</span><span class="token number">50</span><span class="token punctuation">)</span>
	pdf<span class="token punctuation">.</span><span class="token function">Bookmark</span><span class="token punctuation">(</span><span class="token string">"Paragraph 2"</span><span class="token punctuation">,</span> <span class="token number">1</span><span class="token punctuation">,</span> <span class="token operator">-</span><span class="token number">1</span><span class="token punctuation">)</span>
	pdf<span class="token punctuation">.</span><span class="token function">Cell</span><span class="token punctuation">(</span><span class="token number">0</span><span class="token punctuation">,</span> <span class="token number">6</span><span class="token punctuation">,</span> <span class="token string">"Paragraph 2"</span><span class="token punctuation">)</span>
	pdf<span class="token punctuation">.</span><span class="token function">AddPage</span><span class="token punctuation">(</span><span class="token punctuation">)</span>
	pdf<span class="token punctuation">.</span><span class="token function">Bookmark</span><span class="token punctuation">(</span><span class="token string">"Page 2"</span><span class="token punctuation">,</span> <span class="token number">0</span><span class="token punctuation">,</span> <span class="token number">0</span><span class="token punctuation">)</span>
	pdf<span class="token punctuation">.</span><span class="token function">Bookmark</span><span class="token punctuation">(</span><span class="token string">"Paragraph 3"</span><span class="token punctuation">,</span> <span class="token number">1</span><span class="token punctuation">,</span> <span class="token operator">-</span><span class="token number">1</span><span class="token punctuation">)</span>
	pdf<span class="token punctuation">.</span><span class="token function">Cell</span><span class="token punctuation">(</span><span class="token number">0</span><span class="token punctuation">,</span> <span class="token number">6</span><span class="token punctuation">,</span> <span class="token string">"Paragraph 3"</span><span class="token punctuation">)</span>
	fileStr <span class="token operator">:=</span> example<span class="token punctuation">.</span><span class="token function">Filename</span><span class="token punctuation">(</span><span class="token string">"Fpdf_Bookmark"</span><span class="token punctuation">)</span>
	err <span class="token operator">:=</span> pdf<span class="token punctuation">.</span><span class="token function">OutputFileAndClose</span><span class="token punctuation">(</span>fileStr<span class="token punctuation">)</span>
	example<span class="token punctuation">.</span><span class="token function">Summary</span><span class="token punctuation">(</span>err<span class="token punctuation">,</span> fileStr<span class="token punctuation">)</span>
	<span class="token comment">// Output:</span>
	<span class="token comment">// Successfully generated pdf/Fpdf_Bookmark.pdf</span>
<span class="token punctuation">&#125;</span></code></pre>

<h2 id="演示各种转换"><a href="#演示各种转换" class="headerlink" title="演示各种转换"></a>演示各种转换</h2><p>它改编自Moritz Wagner和Andreas Würmser的示例脚本</p>
<pre class="language-go" data-language="go"><code class="language-go"><span class="token comment">// ExampleFpdf_TransformBegin demonstrates various transformations. It is adapted from an</span>
<span class="token comment">// example script by Moritz Wagner and Andreas Würmser.</span>
<span class="token keyword">func</span> <span class="token function">ExampleFpdf_TransformBegin</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">&#123;</span>
	<span class="token keyword">const</span> <span class="token punctuation">(</span>
		light <span class="token operator">=</span> <span class="token number">200</span>
		dark  <span class="token operator">=</span> <span class="token number">0</span>
	<span class="token punctuation">)</span>
	<span class="token keyword">var</span> refX<span class="token punctuation">,</span> refY <span class="token builtin">float64</span>
	<span class="token keyword">var</span> refStr <span class="token builtin">string</span>
	pdf <span class="token operator">:=</span> gofpdf<span class="token punctuation">.</span><span class="token function">New</span><span class="token punctuation">(</span><span class="token string">"P"</span><span class="token punctuation">,</span> <span class="token string">"mm"</span><span class="token punctuation">,</span> <span class="token string">"A4"</span><span class="token punctuation">,</span> <span class="token string">""</span><span class="token punctuation">)</span>
	pdf<span class="token punctuation">.</span><span class="token function">AddPage</span><span class="token punctuation">(</span><span class="token punctuation">)</span>
	color <span class="token operator">:=</span> <span class="token keyword">func</span><span class="token punctuation">(</span>val <span class="token builtin">int</span><span class="token punctuation">)</span> <span class="token punctuation">&#123;</span>
		pdf<span class="token punctuation">.</span><span class="token function">SetDrawColor</span><span class="token punctuation">(</span>val<span class="token punctuation">,</span> val<span class="token punctuation">,</span> val<span class="token punctuation">)</span>
		pdf<span class="token punctuation">.</span><span class="token function">SetTextColor</span><span class="token punctuation">(</span>val<span class="token punctuation">,</span> val<span class="token punctuation">,</span> val<span class="token punctuation">)</span>
	<span class="token punctuation">&#125;</span>
	reference <span class="token operator">:=</span> <span class="token keyword">func</span><span class="token punctuation">(</span>str <span class="token builtin">string</span><span class="token punctuation">,</span> x<span class="token punctuation">,</span> y <span class="token builtin">float64</span><span class="token punctuation">,</span> val <span class="token builtin">int</span><span class="token punctuation">)</span> <span class="token punctuation">&#123;</span>
		<span class="token function">color</span><span class="token punctuation">(</span>val<span class="token punctuation">)</span>
		pdf<span class="token punctuation">.</span><span class="token function">Rect</span><span class="token punctuation">(</span>x<span class="token punctuation">,</span> y<span class="token punctuation">,</span> <span class="token number">40</span><span class="token punctuation">,</span> <span class="token number">10</span><span class="token punctuation">,</span> <span class="token string">"D"</span><span class="token punctuation">)</span>
		pdf<span class="token punctuation">.</span><span class="token function">Text</span><span class="token punctuation">(</span>x<span class="token punctuation">,</span> y<span class="token operator">-</span><span class="token number">1</span><span class="token punctuation">,</span> str<span class="token punctuation">)</span>
	<span class="token punctuation">&#125;</span>
	refDraw <span class="token operator">:=</span> <span class="token keyword">func</span><span class="token punctuation">(</span>str <span class="token builtin">string</span><span class="token punctuation">,</span> x<span class="token punctuation">,</span> y <span class="token builtin">float64</span><span class="token punctuation">)</span> <span class="token punctuation">&#123;</span>
		refStr <span class="token operator">=</span> str
		refX <span class="token operator">=</span> x
		refY <span class="token operator">=</span> y
		<span class="token function">reference</span><span class="token punctuation">(</span>str<span class="token punctuation">,</span> x<span class="token punctuation">,</span> y<span class="token punctuation">,</span> light<span class="token punctuation">)</span>
	<span class="token punctuation">&#125;</span>
	refDupe <span class="token operator">:=</span> <span class="token keyword">func</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">&#123;</span>
		<span class="token function">reference</span><span class="token punctuation">(</span>refStr<span class="token punctuation">,</span> refX<span class="token punctuation">,</span> refY<span class="token punctuation">,</span> dark<span class="token punctuation">)</span>
	<span class="token punctuation">&#125;</span>

	titleStr <span class="token operator">:=</span> <span class="token string">"Transformations"</span>
	titlePt <span class="token operator">:=</span> <span class="token number">36.0</span>
	titleHt <span class="token operator">:=</span> pdf<span class="token punctuation">.</span><span class="token function">PointConvert</span><span class="token punctuation">(</span>titlePt<span class="token punctuation">)</span>
	pdf<span class="token punctuation">.</span><span class="token function">SetFont</span><span class="token punctuation">(</span><span class="token string">"Helvetica"</span><span class="token punctuation">,</span> <span class="token string">""</span><span class="token punctuation">,</span> titlePt<span class="token punctuation">)</span>
	titleWd <span class="token operator">:=</span> pdf<span class="token punctuation">.</span><span class="token function">GetStringWidth</span><span class="token punctuation">(</span>titleStr<span class="token punctuation">)</span>
	titleX <span class="token operator">:=</span> <span class="token punctuation">(</span><span class="token number">210</span> <span class="token operator">-</span> titleWd<span class="token punctuation">)</span> <span class="token operator">/</span> <span class="token number">2</span>
	pdf<span class="token punctuation">.</span><span class="token function">Text</span><span class="token punctuation">(</span>titleX<span class="token punctuation">,</span> <span class="token number">10</span><span class="token operator">+</span>titleHt<span class="token punctuation">,</span> titleStr<span class="token punctuation">)</span>
	pdf<span class="token punctuation">.</span><span class="token function">TransformBegin</span><span class="token punctuation">(</span><span class="token punctuation">)</span>
	pdf<span class="token punctuation">.</span><span class="token function">TransformMirrorVertical</span><span class="token punctuation">(</span><span class="token number">10</span> <span class="token operator">+</span> titleHt <span class="token operator">+</span> <span class="token number">0.5</span><span class="token punctuation">)</span>
	pdf<span class="token punctuation">.</span><span class="token function">ClipText</span><span class="token punctuation">(</span>titleX<span class="token punctuation">,</span> <span class="token number">10</span><span class="token operator">+</span>titleHt<span class="token punctuation">,</span> titleStr<span class="token punctuation">,</span> <span class="token boolean">false</span><span class="token punctuation">)</span>
	<span class="token comment">// Remember that the transform will mirror the gradient box too</span>
	pdf<span class="token punctuation">.</span><span class="token function">LinearGradient</span><span class="token punctuation">(</span>titleX<span class="token punctuation">,</span> <span class="token number">10</span><span class="token punctuation">,</span> titleWd<span class="token punctuation">,</span> titleHt<span class="token operator">+</span><span class="token number">4</span><span class="token punctuation">,</span> <span class="token number">120</span><span class="token punctuation">,</span> <span class="token number">120</span><span class="token punctuation">,</span> <span class="token number">120</span><span class="token punctuation">,</span>
		<span class="token number">255</span><span class="token punctuation">,</span> <span class="token number">255</span><span class="token punctuation">,</span> <span class="token number">255</span><span class="token punctuation">,</span> <span class="token number">0</span><span class="token punctuation">,</span> <span class="token number">0</span><span class="token punctuation">,</span> <span class="token number">0</span><span class="token punctuation">,</span> <span class="token number">0.6</span><span class="token punctuation">)</span>
	pdf<span class="token punctuation">.</span><span class="token function">ClipEnd</span><span class="token punctuation">(</span><span class="token punctuation">)</span>
	pdf<span class="token punctuation">.</span><span class="token function">TransformEnd</span><span class="token punctuation">(</span><span class="token punctuation">)</span>

	pdf<span class="token punctuation">.</span><span class="token function">SetFont</span><span class="token punctuation">(</span><span class="token string">"Helvetica"</span><span class="token punctuation">,</span> <span class="token string">""</span><span class="token punctuation">,</span> <span class="token number">12</span><span class="token punctuation">)</span>

	<span class="token comment">// Scale by 150% centered by lower left corner of the rectangle</span>
	<span class="token function">refDraw</span><span class="token punctuation">(</span><span class="token string">"Scale"</span><span class="token punctuation">,</span> <span class="token number">50</span><span class="token punctuation">,</span> <span class="token number">60</span><span class="token punctuation">)</span>
	pdf<span class="token punctuation">.</span><span class="token function">TransformBegin</span><span class="token punctuation">(</span><span class="token punctuation">)</span>
	pdf<span class="token punctuation">.</span><span class="token function">TransformScaleXY</span><span class="token punctuation">(</span><span class="token number">150</span><span class="token punctuation">,</span> <span class="token number">50</span><span class="token punctuation">,</span> <span class="token number">70</span><span class="token punctuation">)</span>
	<span class="token function">refDupe</span><span class="token punctuation">(</span><span class="token punctuation">)</span>
	pdf<span class="token punctuation">.</span><span class="token function">TransformEnd</span><span class="token punctuation">(</span><span class="token punctuation">)</span>

	<span class="token comment">// Translate 7 to the right, 5 to the bottom</span>
	<span class="token function">refDraw</span><span class="token punctuation">(</span><span class="token string">"Translate"</span><span class="token punctuation">,</span> <span class="token number">125</span><span class="token punctuation">,</span> <span class="token number">60</span><span class="token punctuation">)</span>
	pdf<span class="token punctuation">.</span><span class="token function">TransformBegin</span><span class="token punctuation">(</span><span class="token punctuation">)</span>
	pdf<span class="token punctuation">.</span><span class="token function">TransformTranslate</span><span class="token punctuation">(</span><span class="token number">7</span><span class="token punctuation">,</span> <span class="token number">5</span><span class="token punctuation">)</span>
	<span class="token function">refDupe</span><span class="token punctuation">(</span><span class="token punctuation">)</span>
	pdf<span class="token punctuation">.</span><span class="token function">TransformEnd</span><span class="token punctuation">(</span><span class="token punctuation">)</span>

	<span class="token comment">// Rotate 20 degrees counter-clockwise centered by the lower left corner of</span>
	<span class="token comment">// the rectangle</span>
	<span class="token function">refDraw</span><span class="token punctuation">(</span><span class="token string">"Rotate"</span><span class="token punctuation">,</span> <span class="token number">50</span><span class="token punctuation">,</span> <span class="token number">110</span><span class="token punctuation">)</span>
	pdf<span class="token punctuation">.</span><span class="token function">TransformBegin</span><span class="token punctuation">(</span><span class="token punctuation">)</span>
	pdf<span class="token punctuation">.</span><span class="token function">TransformRotate</span><span class="token punctuation">(</span><span class="token number">20</span><span class="token punctuation">,</span> <span class="token number">50</span><span class="token punctuation">,</span> <span class="token number">120</span><span class="token punctuation">)</span>
	<span class="token function">refDupe</span><span class="token punctuation">(</span><span class="token punctuation">)</span>
	pdf<span class="token punctuation">.</span><span class="token function">TransformEnd</span><span class="token punctuation">(</span><span class="token punctuation">)</span>

	<span class="token comment">// Skew 30 degrees along the x-axis centered by the lower left corner of the</span>
	<span class="token comment">// rectangle</span>
	<span class="token function">refDraw</span><span class="token punctuation">(</span><span class="token string">"Skew"</span><span class="token punctuation">,</span> <span class="token number">125</span><span class="token punctuation">,</span> <span class="token number">110</span><span class="token punctuation">)</span>
	pdf<span class="token punctuation">.</span><span class="token function">TransformBegin</span><span class="token punctuation">(</span><span class="token punctuation">)</span>
	pdf<span class="token punctuation">.</span><span class="token function">TransformSkewX</span><span class="token punctuation">(</span><span class="token number">30</span><span class="token punctuation">,</span> <span class="token number">125</span><span class="token punctuation">,</span> <span class="token number">110</span><span class="token punctuation">)</span>
	<span class="token function">refDupe</span><span class="token punctuation">(</span><span class="token punctuation">)</span>
	pdf<span class="token punctuation">.</span><span class="token function">TransformEnd</span><span class="token punctuation">(</span><span class="token punctuation">)</span>

	<span class="token comment">// Mirror horizontally with axis of reflection at left side of the rectangle</span>
	<span class="token function">refDraw</span><span class="token punctuation">(</span><span class="token string">"Mirror horizontal"</span><span class="token punctuation">,</span> <span class="token number">50</span><span class="token punctuation">,</span> <span class="token number">160</span><span class="token punctuation">)</span>
	pdf<span class="token punctuation">.</span><span class="token function">TransformBegin</span><span class="token punctuation">(</span><span class="token punctuation">)</span>
	pdf<span class="token punctuation">.</span><span class="token function">TransformMirrorHorizontal</span><span class="token punctuation">(</span><span class="token number">50</span><span class="token punctuation">)</span>
	<span class="token function">refDupe</span><span class="token punctuation">(</span><span class="token punctuation">)</span>
	pdf<span class="token punctuation">.</span><span class="token function">TransformEnd</span><span class="token punctuation">(</span><span class="token punctuation">)</span>

	<span class="token comment">// Mirror vertically with axis of reflection at bottom side of the rectangle</span>
	<span class="token function">refDraw</span><span class="token punctuation">(</span><span class="token string">"Mirror vertical"</span><span class="token punctuation">,</span> <span class="token number">125</span><span class="token punctuation">,</span> <span class="token number">160</span><span class="token punctuation">)</span>
	pdf<span class="token punctuation">.</span><span class="token function">TransformBegin</span><span class="token punctuation">(</span><span class="token punctuation">)</span>
	pdf<span class="token punctuation">.</span><span class="token function">TransformMirrorVertical</span><span class="token punctuation">(</span><span class="token number">170</span><span class="token punctuation">)</span>
	<span class="token function">refDupe</span><span class="token punctuation">(</span><span class="token punctuation">)</span>
	pdf<span class="token punctuation">.</span><span class="token function">TransformEnd</span><span class="token punctuation">(</span><span class="token punctuation">)</span>

	<span class="token comment">// Reflect against a point at the lower left point of rectangle</span>
	<span class="token function">refDraw</span><span class="token punctuation">(</span><span class="token string">"Mirror point"</span><span class="token punctuation">,</span> <span class="token number">50</span><span class="token punctuation">,</span> <span class="token number">210</span><span class="token punctuation">)</span>
	pdf<span class="token punctuation">.</span><span class="token function">TransformBegin</span><span class="token punctuation">(</span><span class="token punctuation">)</span>
	pdf<span class="token punctuation">.</span><span class="token function">TransformMirrorPoint</span><span class="token punctuation">(</span><span class="token number">50</span><span class="token punctuation">,</span> <span class="token number">220</span><span class="token punctuation">)</span>
	<span class="token function">refDupe</span><span class="token punctuation">(</span><span class="token punctuation">)</span>
	pdf<span class="token punctuation">.</span><span class="token function">TransformEnd</span><span class="token punctuation">(</span><span class="token punctuation">)</span>

	<span class="token comment">// Mirror against a straight line described by a point and an angle</span>
	angle <span class="token operator">:=</span> <span class="token operator">-</span><span class="token number">20.0</span>
	px <span class="token operator">:=</span> <span class="token number">120.0</span>
	py <span class="token operator">:=</span> <span class="token number">220.0</span>
	<span class="token function">refDraw</span><span class="token punctuation">(</span><span class="token string">"Mirror line"</span><span class="token punctuation">,</span> <span class="token number">125</span><span class="token punctuation">,</span> <span class="token number">210</span><span class="token punctuation">)</span>
	pdf<span class="token punctuation">.</span><span class="token function">TransformBegin</span><span class="token punctuation">(</span><span class="token punctuation">)</span>
	pdf<span class="token punctuation">.</span><span class="token function">TransformRotate</span><span class="token punctuation">(</span>angle<span class="token punctuation">,</span> px<span class="token punctuation">,</span> py<span class="token punctuation">)</span>
	pdf<span class="token punctuation">.</span><span class="token function">Line</span><span class="token punctuation">(</span>px<span class="token operator">-</span><span class="token number">1</span><span class="token punctuation">,</span> py<span class="token operator">-</span><span class="token number">1</span><span class="token punctuation">,</span> px<span class="token operator">+</span><span class="token number">1</span><span class="token punctuation">,</span> py<span class="token operator">+</span><span class="token number">1</span><span class="token punctuation">)</span>
	pdf<span class="token punctuation">.</span><span class="token function">Line</span><span class="token punctuation">(</span>px<span class="token operator">-</span><span class="token number">1</span><span class="token punctuation">,</span> py<span class="token operator">+</span><span class="token number">1</span><span class="token punctuation">,</span> px<span class="token operator">+</span><span class="token number">1</span><span class="token punctuation">,</span> py<span class="token operator">-</span><span class="token number">1</span><span class="token punctuation">)</span>
	pdf<span class="token punctuation">.</span><span class="token function">Line</span><span class="token punctuation">(</span>px<span class="token operator">-</span><span class="token number">5</span><span class="token punctuation">,</span> py<span class="token punctuation">,</span> px<span class="token operator">+</span><span class="token number">60</span><span class="token punctuation">,</span> py<span class="token punctuation">)</span>
	pdf<span class="token punctuation">.</span><span class="token function">TransformEnd</span><span class="token punctuation">(</span><span class="token punctuation">)</span>
	pdf<span class="token punctuation">.</span><span class="token function">TransformBegin</span><span class="token punctuation">(</span><span class="token punctuation">)</span>
	pdf<span class="token punctuation">.</span><span class="token function">TransformMirrorLine</span><span class="token punctuation">(</span>angle<span class="token punctuation">,</span> px<span class="token punctuation">,</span> py<span class="token punctuation">)</span>
	<span class="token function">refDupe</span><span class="token punctuation">(</span><span class="token punctuation">)</span>
	pdf<span class="token punctuation">.</span><span class="token function">TransformEnd</span><span class="token punctuation">(</span><span class="token punctuation">)</span>

	fileStr <span class="token operator">:=</span> example<span class="token punctuation">.</span><span class="token function">Filename</span><span class="token punctuation">(</span><span class="token string">"Fpdf_TransformBegin"</span><span class="token punctuation">)</span>
	err <span class="token operator">:=</span> pdf<span class="token punctuation">.</span><span class="token function">OutputFileAndClose</span><span class="token punctuation">(</span>fileStr<span class="token punctuation">)</span>
	example<span class="token punctuation">.</span><span class="token function">Summary</span><span class="token punctuation">(</span>err<span class="token punctuation">,</span> fileStr<span class="token punctuation">)</span>
	<span class="token comment">// Output:</span>
	<span class="token comment">// Successfully generated pdf/Fpdf_TransformBegin.pdf</span>
<span class="token punctuation">&#125;</span></code></pre>

<h2 id="演示Lawrence-Kesteloot的图像注册代码"><a href="#演示Lawrence-Kesteloot的图像注册代码" class="headerlink" title="演示Lawrence Kesteloot的图像注册代码"></a>演示Lawrence Kesteloot的图像注册代码</h2><pre class="language-go" data-language="go"><code class="language-go"><span class="token comment">// ExampleFpdf_RegisterImage demonstrates Lawrence Kesteloot's image registration code.</span>
<span class="token keyword">func</span> <span class="token function">ExampleFpdf_RegisterImage</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">&#123;</span>
	<span class="token keyword">const</span> <span class="token punctuation">(</span>
		margin <span class="token operator">=</span> <span class="token number">10</span>
		wd     <span class="token operator">=</span> <span class="token number">210</span>
		ht     <span class="token operator">=</span> <span class="token number">297</span>
	<span class="token punctuation">)</span>
	fileList <span class="token operator">:=</span> <span class="token punctuation">[</span><span class="token punctuation">]</span><span class="token builtin">string</span><span class="token punctuation">&#123;</span>
		<span class="token string">"logo-gray.png"</span><span class="token punctuation">,</span>
		<span class="token string">"logo.jpg"</span><span class="token punctuation">,</span>
		<span class="token string">"logo.png"</span><span class="token punctuation">,</span>
		<span class="token string">"logo-rgb.png"</span><span class="token punctuation">,</span>
		<span class="token string">"logo-progressive.jpg"</span><span class="token punctuation">,</span>
	<span class="token punctuation">&#125;</span>
	<span class="token keyword">var</span> infoPtr <span class="token operator">*</span>gofpdf<span class="token punctuation">.</span>ImageInfoType
	<span class="token keyword">var</span> imageFileStr <span class="token builtin">string</span>
	<span class="token keyword">var</span> imgWd<span class="token punctuation">,</span> imgHt<span class="token punctuation">,</span> lf<span class="token punctuation">,</span> tp <span class="token builtin">float64</span>
	pdf <span class="token operator">:=</span> gofpdf<span class="token punctuation">.</span><span class="token function">New</span><span class="token punctuation">(</span><span class="token string">"P"</span><span class="token punctuation">,</span> <span class="token string">"mm"</span><span class="token punctuation">,</span> <span class="token string">"A4"</span><span class="token punctuation">,</span> <span class="token string">""</span><span class="token punctuation">)</span>
	pdf<span class="token punctuation">.</span><span class="token function">AddPage</span><span class="token punctuation">(</span><span class="token punctuation">)</span>
	pdf<span class="token punctuation">.</span><span class="token function">SetMargins</span><span class="token punctuation">(</span><span class="token number">10</span><span class="token punctuation">,</span> <span class="token number">10</span><span class="token punctuation">,</span> <span class="token number">10</span><span class="token punctuation">)</span>
	pdf<span class="token punctuation">.</span><span class="token function">SetFont</span><span class="token punctuation">(</span><span class="token string">"Helvetica"</span><span class="token punctuation">,</span> <span class="token string">""</span><span class="token punctuation">,</span> <span class="token number">15</span><span class="token punctuation">)</span>
	<span class="token keyword">for</span> j<span class="token punctuation">,</span> str <span class="token operator">:=</span> <span class="token keyword">range</span> fileList <span class="token punctuation">&#123;</span>
		imageFileStr <span class="token operator">=</span> example<span class="token punctuation">.</span><span class="token function">ImageFile</span><span class="token punctuation">(</span>str<span class="token punctuation">)</span>
		infoPtr <span class="token operator">=</span> pdf<span class="token punctuation">.</span><span class="token function">RegisterImage</span><span class="token punctuation">(</span>imageFileStr<span class="token punctuation">,</span> <span class="token string">""</span><span class="token punctuation">)</span>
		imgWd<span class="token punctuation">,</span> imgHt <span class="token operator">=</span> infoPtr<span class="token punctuation">.</span><span class="token function">Extent</span><span class="token punctuation">(</span><span class="token punctuation">)</span>
		<span class="token keyword">switch</span> j <span class="token punctuation">&#123;</span>
		<span class="token keyword">case</span> <span class="token number">0</span><span class="token punctuation">:</span>
			lf <span class="token operator">=</span> margin
			tp <span class="token operator">=</span> margin
		<span class="token keyword">case</span> <span class="token number">1</span><span class="token punctuation">:</span>
			lf <span class="token operator">=</span> wd <span class="token operator">-</span> margin <span class="token operator">-</span> imgWd
			tp <span class="token operator">=</span> margin
		<span class="token keyword">case</span> <span class="token number">2</span><span class="token punctuation">:</span>
			lf <span class="token operator">=</span> <span class="token punctuation">(</span>wd <span class="token operator">-</span> imgWd<span class="token punctuation">)</span> <span class="token operator">/</span> <span class="token number">2.0</span>
			tp <span class="token operator">=</span> <span class="token punctuation">(</span>ht <span class="token operator">-</span> imgHt<span class="token punctuation">)</span> <span class="token operator">/</span> <span class="token number">2.0</span>
		<span class="token keyword">case</span> <span class="token number">3</span><span class="token punctuation">:</span>
			lf <span class="token operator">=</span> margin
			tp <span class="token operator">=</span> ht <span class="token operator">-</span> imgHt <span class="token operator">-</span> margin
		<span class="token keyword">case</span> <span class="token number">4</span><span class="token punctuation">:</span>
			lf <span class="token operator">=</span> wd <span class="token operator">-</span> imgWd <span class="token operator">-</span> margin
			tp <span class="token operator">=</span> ht <span class="token operator">-</span> imgHt <span class="token operator">-</span> margin
		<span class="token punctuation">&#125;</span>
		pdf<span class="token punctuation">.</span><span class="token function">Image</span><span class="token punctuation">(</span>imageFileStr<span class="token punctuation">,</span> lf<span class="token punctuation">,</span> tp<span class="token punctuation">,</span> imgWd<span class="token punctuation">,</span> imgHt<span class="token punctuation">,</span> <span class="token boolean">false</span><span class="token punctuation">,</span> <span class="token string">""</span><span class="token punctuation">,</span> <span class="token number">0</span><span class="token punctuation">,</span> <span class="token string">""</span><span class="token punctuation">)</span>
	<span class="token punctuation">&#125;</span>
	fileStr <span class="token operator">:=</span> example<span class="token punctuation">.</span><span class="token function">Filename</span><span class="token punctuation">(</span><span class="token string">"Fpdf_RegisterImage"</span><span class="token punctuation">)</span>
	<span class="token comment">// Test the image information retrieval method</span>
	infoShow <span class="token operator">:=</span> <span class="token keyword">func</span><span class="token punctuation">(</span>imageStr <span class="token builtin">string</span><span class="token punctuation">)</span> <span class="token punctuation">&#123;</span>
		imageStr <span class="token operator">=</span> example<span class="token punctuation">.</span><span class="token function">ImageFile</span><span class="token punctuation">(</span>imageStr<span class="token punctuation">)</span>
		info <span class="token operator">:=</span> pdf<span class="token punctuation">.</span><span class="token function">GetImageInfo</span><span class="token punctuation">(</span>imageStr<span class="token punctuation">)</span>
		<span class="token keyword">if</span> info <span class="token operator">!=</span> <span class="token boolean">nil</span> <span class="token punctuation">&#123;</span>
			<span class="token keyword">if</span> info<span class="token punctuation">.</span><span class="token function">Width</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token operator">></span> <span class="token number">0.0</span> <span class="token punctuation">&#123;</span>
				fmt<span class="token punctuation">.</span><span class="token function">Printf</span><span class="token punctuation">(</span><span class="token string">"Image %s is registered\n"</span><span class="token punctuation">,</span> filepath<span class="token punctuation">.</span><span class="token function">ToSlash</span><span class="token punctuation">(</span>imageStr<span class="token punctuation">)</span><span class="token punctuation">)</span>
			<span class="token punctuation">&#125;</span> <span class="token keyword">else</span> <span class="token punctuation">&#123;</span>
				fmt<span class="token punctuation">.</span><span class="token function">Printf</span><span class="token punctuation">(</span><span class="token string">"Incorrect information for image %s\n"</span><span class="token punctuation">,</span> filepath<span class="token punctuation">.</span><span class="token function">ToSlash</span><span class="token punctuation">(</span>imageStr<span class="token punctuation">)</span><span class="token punctuation">)</span>
			<span class="token punctuation">&#125;</span>
		<span class="token punctuation">&#125;</span> <span class="token keyword">else</span> <span class="token punctuation">&#123;</span>
			fmt<span class="token punctuation">.</span><span class="token function">Printf</span><span class="token punctuation">(</span><span class="token string">"Image %s is not registered\n"</span><span class="token punctuation">,</span> filepath<span class="token punctuation">.</span><span class="token function">ToSlash</span><span class="token punctuation">(</span>imageStr<span class="token punctuation">)</span><span class="token punctuation">)</span>
		<span class="token punctuation">&#125;</span>
	<span class="token punctuation">&#125;</span>
	<span class="token function">infoShow</span><span class="token punctuation">(</span>fileList<span class="token punctuation">[</span><span class="token number">0</span><span class="token punctuation">]</span><span class="token punctuation">)</span>
	<span class="token function">infoShow</span><span class="token punctuation">(</span><span class="token string">"foo.png"</span><span class="token punctuation">)</span>
	err <span class="token operator">:=</span> pdf<span class="token punctuation">.</span><span class="token function">OutputFileAndClose</span><span class="token punctuation">(</span>fileStr<span class="token punctuation">)</span>
	example<span class="token punctuation">.</span><span class="token function">Summary</span><span class="token punctuation">(</span>err<span class="token punctuation">,</span> fileStr<span class="token punctuation">)</span>
	<span class="token comment">// Output:</span>
	<span class="token comment">// Image image/logo-gray.png is registered</span>
	<span class="token comment">// Image image/foo.png is not registered</span>
	<span class="token comment">// Successfully generated pdf/Fpdf_RegisterImage.pdf</span>
<span class="token punctuation">&#125;</span></code></pre>

<h2 id="演示布鲁诺米歇尔的分线功能"><a href="#演示布鲁诺米歇尔的分线功能" class="headerlink" title="演示布鲁诺米歇尔的分线功能"></a>演示布鲁诺米歇尔的分线功能</h2><pre class="language-go" data-language="go"><code class="language-go"><span class="token comment">// ExampleFpdf_SplitLines demonstrates Bruno Michel's line splitting function.</span>
<span class="token keyword">func</span> <span class="token function">ExampleFpdf_SplitLines</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">&#123;</span>
	<span class="token keyword">const</span> <span class="token punctuation">(</span>
		fontPtSize <span class="token operator">=</span> <span class="token number">18.0</span>
		wd         <span class="token operator">=</span> <span class="token number">100.0</span>
	<span class="token punctuation">)</span>
	pdf <span class="token operator">:=</span> gofpdf<span class="token punctuation">.</span><span class="token function">New</span><span class="token punctuation">(</span><span class="token string">"P"</span><span class="token punctuation">,</span> <span class="token string">"mm"</span><span class="token punctuation">,</span> <span class="token string">"A4"</span><span class="token punctuation">,</span> <span class="token string">""</span><span class="token punctuation">)</span> <span class="token comment">// A4 210.0 x 297.0</span>
	pdf<span class="token punctuation">.</span><span class="token function">SetFont</span><span class="token punctuation">(</span><span class="token string">"Times"</span><span class="token punctuation">,</span> <span class="token string">""</span><span class="token punctuation">,</span> fontPtSize<span class="token punctuation">)</span>
	<span class="token boolean">_</span><span class="token punctuation">,</span> lineHt <span class="token operator">:=</span> pdf<span class="token punctuation">.</span><span class="token function">GetFontSize</span><span class="token punctuation">(</span><span class="token punctuation">)</span>
	pdf<span class="token punctuation">.</span><span class="token function">AddPage</span><span class="token punctuation">(</span><span class="token punctuation">)</span>
	pdf<span class="token punctuation">.</span><span class="token function">SetMargins</span><span class="token punctuation">(</span><span class="token number">10</span><span class="token punctuation">,</span> <span class="token number">10</span><span class="token punctuation">,</span> <span class="token number">10</span><span class="token punctuation">)</span>
	lines <span class="token operator">:=</span> pdf<span class="token punctuation">.</span><span class="token function">SplitLines</span><span class="token punctuation">(</span><span class="token punctuation">[</span><span class="token punctuation">]</span><span class="token function">byte</span><span class="token punctuation">(</span><span class="token function">lorem</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">,</span> wd<span class="token punctuation">)</span>
	ht <span class="token operator">:=</span> <span class="token function">float64</span><span class="token punctuation">(</span><span class="token function">len</span><span class="token punctuation">(</span>lines<span class="token punctuation">)</span><span class="token punctuation">)</span> <span class="token operator">*</span> lineHt
	y <span class="token operator">:=</span> <span class="token punctuation">(</span><span class="token number">297.0</span> <span class="token operator">-</span> ht<span class="token punctuation">)</span> <span class="token operator">/</span> <span class="token number">2.0</span>
	pdf<span class="token punctuation">.</span><span class="token function">SetDrawColor</span><span class="token punctuation">(</span><span class="token number">128</span><span class="token punctuation">,</span> <span class="token number">128</span><span class="token punctuation">,</span> <span class="token number">128</span><span class="token punctuation">)</span>
	pdf<span class="token punctuation">.</span><span class="token function">SetFillColor</span><span class="token punctuation">(</span><span class="token number">255</span><span class="token punctuation">,</span> <span class="token number">255</span><span class="token punctuation">,</span> <span class="token number">210</span><span class="token punctuation">)</span>
	x <span class="token operator">:=</span> <span class="token punctuation">(</span><span class="token number">210.0</span> <span class="token operator">-</span> <span class="token punctuation">(</span>wd <span class="token operator">+</span> <span class="token number">40.0</span><span class="token punctuation">)</span><span class="token punctuation">)</span> <span class="token operator">/</span> <span class="token number">2.0</span>
	pdf<span class="token punctuation">.</span><span class="token function">Rect</span><span class="token punctuation">(</span>x<span class="token punctuation">,</span> y<span class="token operator">-</span><span class="token number">20.0</span><span class="token punctuation">,</span> wd<span class="token operator">+</span><span class="token number">40.0</span><span class="token punctuation">,</span> ht<span class="token operator">+</span><span class="token number">40.0</span><span class="token punctuation">,</span> <span class="token string">"FD"</span><span class="token punctuation">)</span>
	pdf<span class="token punctuation">.</span><span class="token function">SetY</span><span class="token punctuation">(</span>y<span class="token punctuation">)</span>
	<span class="token keyword">for</span> <span class="token boolean">_</span><span class="token punctuation">,</span> line <span class="token operator">:=</span> <span class="token keyword">range</span> lines <span class="token punctuation">&#123;</span>
		pdf<span class="token punctuation">.</span><span class="token function">CellFormat</span><span class="token punctuation">(</span><span class="token number">190.0</span><span class="token punctuation">,</span> lineHt<span class="token punctuation">,</span> <span class="token function">string</span><span class="token punctuation">(</span>line<span class="token punctuation">)</span><span class="token punctuation">,</span> <span class="token string">""</span><span class="token punctuation">,</span> <span class="token number">1</span><span class="token punctuation">,</span> <span class="token string">"C"</span><span class="token punctuation">,</span> <span class="token boolean">false</span><span class="token punctuation">,</span> <span class="token number">0</span><span class="token punctuation">,</span> <span class="token string">""</span><span class="token punctuation">)</span>
	<span class="token punctuation">&#125;</span>
	fileStr <span class="token operator">:=</span> example<span class="token punctuation">.</span><span class="token function">Filename</span><span class="token punctuation">(</span><span class="token string">"Fpdf_Splitlines"</span><span class="token punctuation">)</span>
	err <span class="token operator">:=</span> pdf<span class="token punctuation">.</span><span class="token function">OutputFileAndClose</span><span class="token punctuation">(</span>fileStr<span class="token punctuation">)</span>
	example<span class="token punctuation">.</span><span class="token function">Summary</span><span class="token punctuation">(</span>err<span class="token punctuation">,</span> fileStr<span class="token punctuation">)</span>
	<span class="token comment">// Output:</span>
<span class="token punctuation">&#125;</span></code></pre>

<h2 id="演示如何呈现由jSignature-web控件生成的类型的简单纯路径SVG图像"><a href="#演示如何呈现由jSignature-web控件生成的类型的简单纯路径SVG图像" class="headerlink" title="演示如何呈现由jSignature web控件生成的类型的简单纯路径SVG图像"></a>演示如何呈现由jSignature web控件生成的类型的简单纯路径SVG图像</h2><pre class="language-go" data-language="go"><code class="language-go"><span class="token comment">// ExampleFpdf_SVGBasicWrite demonstrates how to render a simple path-only SVG image of the</span>
<span class="token comment">// type generated by the jSignature web control.</span>
<span class="token keyword">func</span> <span class="token function">ExampleFpdf_SVGBasicWrite</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">&#123;</span>
	<span class="token keyword">const</span> <span class="token punctuation">(</span>
		fontPtSize <span class="token operator">=</span> <span class="token number">16.0</span>
		wd         <span class="token operator">=</span> <span class="token number">100.0</span>
		sigFileStr <span class="token operator">=</span> <span class="token string">"signature.svg"</span>
	<span class="token punctuation">)</span>
	<span class="token keyword">var</span> <span class="token punctuation">(</span>
		sig gofpdf<span class="token punctuation">.</span>SVGBasicType
		err <span class="token builtin">error</span>
	<span class="token punctuation">)</span>
	pdf <span class="token operator">:=</span> gofpdf<span class="token punctuation">.</span><span class="token function">New</span><span class="token punctuation">(</span><span class="token string">"P"</span><span class="token punctuation">,</span> <span class="token string">"mm"</span><span class="token punctuation">,</span> <span class="token string">"A4"</span><span class="token punctuation">,</span> <span class="token string">""</span><span class="token punctuation">)</span> <span class="token comment">// A4 210.0 x 297.0</span>
	pdf<span class="token punctuation">.</span><span class="token function">SetFont</span><span class="token punctuation">(</span><span class="token string">"Times"</span><span class="token punctuation">,</span> <span class="token string">""</span><span class="token punctuation">,</span> fontPtSize<span class="token punctuation">)</span>
	lineHt <span class="token operator">:=</span> pdf<span class="token punctuation">.</span><span class="token function">PointConvert</span><span class="token punctuation">(</span>fontPtSize<span class="token punctuation">)</span>
	pdf<span class="token punctuation">.</span><span class="token function">AddPage</span><span class="token punctuation">(</span><span class="token punctuation">)</span>
	pdf<span class="token punctuation">.</span><span class="token function">SetMargins</span><span class="token punctuation">(</span><span class="token number">10</span><span class="token punctuation">,</span> <span class="token number">10</span><span class="token punctuation">,</span> <span class="token number">10</span><span class="token punctuation">)</span>
	htmlStr <span class="token operator">:=</span> <span class="token string">`This example renders a simple `</span> <span class="token operator">+</span>
		<span class="token string">`&lt;a href="http://www.w3.org/TR/SVG/">SVG&lt;/a> (scalable vector graphics) `</span> <span class="token operator">+</span>
		<span class="token string">`image that contains only basic path commands without any styling, `</span> <span class="token operator">+</span>
		<span class="token string">`color fill, reflection or endpoint closures. In particular, the `</span> <span class="token operator">+</span>
		<span class="token string">`type of vector graphic returned from a `</span> <span class="token operator">+</span>
		<span class="token string">`&lt;a href="http://willowsystems.github.io/jSignature/#/demo/">jSignature&lt;/a> `</span> <span class="token operator">+</span>
		<span class="token string">`web control is supported and is used in this example.`</span>
	html <span class="token operator">:=</span> pdf<span class="token punctuation">.</span><span class="token function">HTMLBasicNew</span><span class="token punctuation">(</span><span class="token punctuation">)</span>
	html<span class="token punctuation">.</span><span class="token function">Write</span><span class="token punctuation">(</span>lineHt<span class="token punctuation">,</span> htmlStr<span class="token punctuation">)</span>
	sig<span class="token punctuation">,</span> err <span class="token operator">=</span> gofpdf<span class="token punctuation">.</span><span class="token function">SVGBasicFileParse</span><span class="token punctuation">(</span>example<span class="token punctuation">.</span><span class="token function">ImageFile</span><span class="token punctuation">(</span>sigFileStr<span class="token punctuation">)</span><span class="token punctuation">)</span>
	<span class="token keyword">if</span> err <span class="token operator">==</span> <span class="token boolean">nil</span> <span class="token punctuation">&#123;</span>
		scale <span class="token operator">:=</span> <span class="token number">100</span> <span class="token operator">/</span> sig<span class="token punctuation">.</span>Wd
		scaleY <span class="token operator">:=</span> <span class="token number">30</span> <span class="token operator">/</span> sig<span class="token punctuation">.</span>Ht
		<span class="token keyword">if</span> scale <span class="token operator">></span> scaleY <span class="token punctuation">&#123;</span>
			scale <span class="token operator">=</span> scaleY
		<span class="token punctuation">&#125;</span>
		pdf<span class="token punctuation">.</span><span class="token function">SetLineCapStyle</span><span class="token punctuation">(</span><span class="token string">"round"</span><span class="token punctuation">)</span>
		pdf<span class="token punctuation">.</span><span class="token function">SetLineWidth</span><span class="token punctuation">(</span><span class="token number">0.25</span><span class="token punctuation">)</span>
		pdf<span class="token punctuation">.</span><span class="token function">SetDrawColor</span><span class="token punctuation">(</span><span class="token number">0</span><span class="token punctuation">,</span> <span class="token number">0</span><span class="token punctuation">,</span> <span class="token number">128</span><span class="token punctuation">)</span>
		pdf<span class="token punctuation">.</span><span class="token function">SetXY</span><span class="token punctuation">(</span><span class="token punctuation">(</span><span class="token number">210.0</span><span class="token operator">-</span>scale<span class="token operator">*</span>sig<span class="token punctuation">.</span>Wd<span class="token punctuation">)</span><span class="token operator">/</span><span class="token number">2.0</span><span class="token punctuation">,</span> pdf<span class="token punctuation">.</span><span class="token function">GetY</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token operator">+</span><span class="token number">10</span><span class="token punctuation">)</span>
		pdf<span class="token punctuation">.</span><span class="token function">SVGBasicWrite</span><span class="token punctuation">(</span><span class="token operator">&amp;</span>sig<span class="token punctuation">,</span> scale<span class="token punctuation">)</span>
	<span class="token punctuation">&#125;</span> <span class="token keyword">else</span> <span class="token punctuation">&#123;</span>
		pdf<span class="token punctuation">.</span><span class="token function">SetError</span><span class="token punctuation">(</span>err<span class="token punctuation">)</span>
	<span class="token punctuation">&#125;</span>
	fileStr <span class="token operator">:=</span> example<span class="token punctuation">.</span><span class="token function">Filename</span><span class="token punctuation">(</span><span class="token string">"Fpdf_SVGBasicWrite"</span><span class="token punctuation">)</span>
	err <span class="token operator">=</span> pdf<span class="token punctuation">.</span><span class="token function">OutputFileAndClose</span><span class="token punctuation">(</span>fileStr<span class="token punctuation">)</span>
	example<span class="token punctuation">.</span><span class="token function">Summary</span><span class="token punctuation">(</span>err<span class="token punctuation">,</span> fileStr<span class="token punctuation">)</span>
	<span class="token comment">// Output:</span>
	<span class="token comment">// Successfully generated pdf/Fpdf_SVGBasicWrite.pdf</span>
<span class="token punctuation">&#125;</span></code></pre>

<h2 id="演示了Stefan-Schroeder的代码来控制垂直对齐"><a href="#演示了Stefan-Schroeder的代码来控制垂直对齐" class="headerlink" title="演示了Stefan Schroeder的代码来控制垂直对齐"></a>演示了Stefan Schroeder的代码来控制垂直对齐</h2><pre class="language-go" data-language="go"><code class="language-go"><span class="token comment">// ExampleFpdf_CellFormat_align demonstrates Stefan Schroeder's code to control vertical</span>
<span class="token comment">// alignment.</span>
<span class="token keyword">func</span> <span class="token function">ExampleFpdf_CellFormat_align</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">&#123;</span>
	<span class="token keyword">type</span> recType <span class="token keyword">struct</span> <span class="token punctuation">&#123;</span>
		align<span class="token punctuation">,</span> txt <span class="token builtin">string</span>
	<span class="token punctuation">&#125;</span>
	recList <span class="token operator">:=</span> <span class="token punctuation">[</span><span class="token punctuation">]</span>recType<span class="token punctuation">&#123;</span>
		<span class="token punctuation">&#123;</span><span class="token string">"TL"</span><span class="token punctuation">,</span> <span class="token string">"top left"</span><span class="token punctuation">&#125;</span><span class="token punctuation">,</span>
		<span class="token punctuation">&#123;</span><span class="token string">"TC"</span><span class="token punctuation">,</span> <span class="token string">"top center"</span><span class="token punctuation">&#125;</span><span class="token punctuation">,</span>
		<span class="token punctuation">&#123;</span><span class="token string">"TR"</span><span class="token punctuation">,</span> <span class="token string">"top right"</span><span class="token punctuation">&#125;</span><span class="token punctuation">,</span>
		<span class="token punctuation">&#123;</span><span class="token string">"LM"</span><span class="token punctuation">,</span> <span class="token string">"middle left"</span><span class="token punctuation">&#125;</span><span class="token punctuation">,</span>
		<span class="token punctuation">&#123;</span><span class="token string">"CM"</span><span class="token punctuation">,</span> <span class="token string">"middle center"</span><span class="token punctuation">&#125;</span><span class="token punctuation">,</span>
		<span class="token punctuation">&#123;</span><span class="token string">"RM"</span><span class="token punctuation">,</span> <span class="token string">"middle right"</span><span class="token punctuation">&#125;</span><span class="token punctuation">,</span>
		<span class="token punctuation">&#123;</span><span class="token string">"BL"</span><span class="token punctuation">,</span> <span class="token string">"bottom left"</span><span class="token punctuation">&#125;</span><span class="token punctuation">,</span>
		<span class="token punctuation">&#123;</span><span class="token string">"BC"</span><span class="token punctuation">,</span> <span class="token string">"bottom center"</span><span class="token punctuation">&#125;</span><span class="token punctuation">,</span>
		<span class="token punctuation">&#123;</span><span class="token string">"BR"</span><span class="token punctuation">,</span> <span class="token string">"bottom right"</span><span class="token punctuation">&#125;</span><span class="token punctuation">,</span>
	<span class="token punctuation">&#125;</span>
	recListBaseline <span class="token operator">:=</span> <span class="token punctuation">[</span><span class="token punctuation">]</span>recType<span class="token punctuation">&#123;</span>
		<span class="token punctuation">&#123;</span><span class="token string">"AL"</span><span class="token punctuation">,</span> <span class="token string">"baseline left"</span><span class="token punctuation">&#125;</span><span class="token punctuation">,</span>
		<span class="token punctuation">&#123;</span><span class="token string">"AC"</span><span class="token punctuation">,</span> <span class="token string">"baseline center"</span><span class="token punctuation">&#125;</span><span class="token punctuation">,</span>
		<span class="token punctuation">&#123;</span><span class="token string">"AR"</span><span class="token punctuation">,</span> <span class="token string">"baseline right"</span><span class="token punctuation">&#125;</span><span class="token punctuation">,</span>
	<span class="token punctuation">&#125;</span>
	<span class="token keyword">var</span> formatRect <span class="token operator">=</span> <span class="token keyword">func</span><span class="token punctuation">(</span>pdf <span class="token operator">*</span>gofpdf<span class="token punctuation">.</span>Fpdf<span class="token punctuation">,</span> recList <span class="token punctuation">[</span><span class="token punctuation">]</span>recType<span class="token punctuation">)</span> <span class="token punctuation">&#123;</span>
		linkStr <span class="token operator">:=</span> <span class="token string">""</span>
		<span class="token keyword">for</span> pageJ <span class="token operator">:=</span> <span class="token number">0</span><span class="token punctuation">;</span> pageJ <span class="token operator">&lt;</span> <span class="token number">2</span><span class="token punctuation">;</span> pageJ<span class="token operator">++</span> <span class="token punctuation">&#123;</span>
			pdf<span class="token punctuation">.</span><span class="token function">AddPage</span><span class="token punctuation">(</span><span class="token punctuation">)</span>
			pdf<span class="token punctuation">.</span><span class="token function">SetMargins</span><span class="token punctuation">(</span><span class="token number">10</span><span class="token punctuation">,</span> <span class="token number">10</span><span class="token punctuation">,</span> <span class="token number">10</span><span class="token punctuation">)</span>
			pdf<span class="token punctuation">.</span><span class="token function">SetAutoPageBreak</span><span class="token punctuation">(</span><span class="token boolean">false</span><span class="token punctuation">,</span> <span class="token number">0</span><span class="token punctuation">)</span>
			borderStr <span class="token operator">:=</span> <span class="token string">"1"</span>
			<span class="token keyword">for</span> <span class="token boolean">_</span><span class="token punctuation">,</span> rec <span class="token operator">:=</span> <span class="token keyword">range</span> recList <span class="token punctuation">&#123;</span>
				pdf<span class="token punctuation">.</span><span class="token function">SetXY</span><span class="token punctuation">(</span><span class="token number">20</span><span class="token punctuation">,</span> <span class="token number">20</span><span class="token punctuation">)</span>
				pdf<span class="token punctuation">.</span><span class="token function">CellFormat</span><span class="token punctuation">(</span><span class="token number">170</span><span class="token punctuation">,</span> <span class="token number">257</span><span class="token punctuation">,</span> rec<span class="token punctuation">.</span>txt<span class="token punctuation">,</span> borderStr<span class="token punctuation">,</span> <span class="token number">0</span><span class="token punctuation">,</span> rec<span class="token punctuation">.</span>align<span class="token punctuation">,</span> <span class="token boolean">false</span><span class="token punctuation">,</span> <span class="token number">0</span><span class="token punctuation">,</span> linkStr<span class="token punctuation">)</span>
				borderStr <span class="token operator">=</span> <span class="token string">""</span>
			<span class="token punctuation">&#125;</span>
			linkStr <span class="token operator">=</span> <span class="token string">"https://github.com/jung-kurt/gofpdf"</span>
		<span class="token punctuation">&#125;</span>
	<span class="token punctuation">&#125;</span>
	pdf <span class="token operator">:=</span> gofpdf<span class="token punctuation">.</span><span class="token function">New</span><span class="token punctuation">(</span><span class="token string">"P"</span><span class="token punctuation">,</span> <span class="token string">"mm"</span><span class="token punctuation">,</span> <span class="token string">"A4"</span><span class="token punctuation">,</span> <span class="token string">""</span><span class="token punctuation">)</span> <span class="token comment">// A4 210.0 x 297.0</span>
	pdf<span class="token punctuation">.</span><span class="token function">SetFont</span><span class="token punctuation">(</span><span class="token string">"Helvetica"</span><span class="token punctuation">,</span> <span class="token string">""</span><span class="token punctuation">,</span> <span class="token number">16</span><span class="token punctuation">)</span>
	<span class="token function">formatRect</span><span class="token punctuation">(</span>pdf<span class="token punctuation">,</span> recList<span class="token punctuation">)</span>
	<span class="token function">formatRect</span><span class="token punctuation">(</span>pdf<span class="token punctuation">,</span> recListBaseline<span class="token punctuation">)</span>
	<span class="token keyword">var</span> fr fontResourceType
	pdf<span class="token punctuation">.</span><span class="token function">SetFontLoader</span><span class="token punctuation">(</span>fr<span class="token punctuation">)</span>
	pdf<span class="token punctuation">.</span><span class="token function">AddFont</span><span class="token punctuation">(</span><span class="token string">"Calligrapher"</span><span class="token punctuation">,</span> <span class="token string">""</span><span class="token punctuation">,</span> <span class="token string">"calligra.json"</span><span class="token punctuation">)</span>
	pdf<span class="token punctuation">.</span><span class="token function">SetFont</span><span class="token punctuation">(</span><span class="token string">"Calligrapher"</span><span class="token punctuation">,</span> <span class="token string">""</span><span class="token punctuation">,</span> <span class="token number">16</span><span class="token punctuation">)</span>
	<span class="token function">formatRect</span><span class="token punctuation">(</span>pdf<span class="token punctuation">,</span> recListBaseline<span class="token punctuation">)</span>
	fileStr <span class="token operator">:=</span> example<span class="token punctuation">.</span><span class="token function">Filename</span><span class="token punctuation">(</span><span class="token string">"Fpdf_CellFormat_align"</span><span class="token punctuation">)</span>
	err <span class="token operator">:=</span> pdf<span class="token punctuation">.</span><span class="token function">OutputFileAndClose</span><span class="token punctuation">(</span>fileStr<span class="token punctuation">)</span>
	example<span class="token punctuation">.</span><span class="token function">Summary</span><span class="token punctuation">(</span>err<span class="token punctuation">,</span> fileStr<span class="token punctuation">)</span>
	<span class="token comment">// Output:</span>
	<span class="token comment">// Generalized font loader reading calligra.json</span>
	<span class="token comment">// Generalized font loader reading calligra.z</span>
	<span class="token comment">// Successfully generated pdf/Fpdf_CellFormat_align.pdf</span>
<span class="token punctuation">&#125;</span></code></pre>

<h2 id="演示将UTF-8字符串自动转换为8位字体编码"><a href="#演示将UTF-8字符串自动转换为8位字体编码" class="headerlink" title="演示将UTF-8字符串自动转换为8位字体编码"></a>演示将UTF-8字符串自动转换为8位字体编码</h2><pre class="language-go" data-language="go"><code class="language-go"><span class="token comment">// ExampleFpdf_CellFormat_codepage demonstrates the automatic conversion of UTF-8 strings to an</span>
<span class="token comment">// 8-bit font encoding.</span>
<span class="token keyword">func</span> <span class="token function">ExampleFpdf_CellFormat_codepage</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">&#123;</span>
	pdf <span class="token operator">:=</span> gofpdf<span class="token punctuation">.</span><span class="token function">New</span><span class="token punctuation">(</span><span class="token string">"P"</span><span class="token punctuation">,</span> <span class="token string">"mm"</span><span class="token punctuation">,</span> <span class="token string">"A4"</span><span class="token punctuation">,</span> example<span class="token punctuation">.</span><span class="token function">FontDir</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">)</span> <span class="token comment">// A4 210.0 x 297.0</span>
	<span class="token comment">// See documentation for details on how to generate fonts</span>
	pdf<span class="token punctuation">.</span><span class="token function">AddFont</span><span class="token punctuation">(</span><span class="token string">"Helvetica-1251"</span><span class="token punctuation">,</span> <span class="token string">""</span><span class="token punctuation">,</span> <span class="token string">"helvetica_1251.json"</span><span class="token punctuation">)</span>
	pdf<span class="token punctuation">.</span><span class="token function">AddFont</span><span class="token punctuation">(</span><span class="token string">"Helvetica-1253"</span><span class="token punctuation">,</span> <span class="token string">""</span><span class="token punctuation">,</span> <span class="token string">"helvetica_1253.json"</span><span class="token punctuation">)</span>
	fontSize <span class="token operator">:=</span> <span class="token number">16.0</span>
	pdf<span class="token punctuation">.</span><span class="token function">SetFont</span><span class="token punctuation">(</span><span class="token string">"Helvetica"</span><span class="token punctuation">,</span> <span class="token string">""</span><span class="token punctuation">,</span> fontSize<span class="token punctuation">)</span>
	ht <span class="token operator">:=</span> pdf<span class="token punctuation">.</span><span class="token function">PointConvert</span><span class="token punctuation">(</span>fontSize<span class="token punctuation">)</span>
	tr <span class="token operator">:=</span> pdf<span class="token punctuation">.</span><span class="token function">UnicodeTranslatorFromDescriptor</span><span class="token punctuation">(</span><span class="token string">""</span><span class="token punctuation">)</span> <span class="token comment">// "" defaults to "cp1252"</span>
	write <span class="token operator">:=</span> <span class="token keyword">func</span><span class="token punctuation">(</span>str <span class="token builtin">string</span><span class="token punctuation">)</span> <span class="token punctuation">&#123;</span>
		<span class="token comment">// pdf.CellFormat(190, ht, tr(str), "", 1, "C", false, 0, "")</span>
		pdf<span class="token punctuation">.</span><span class="token function">MultiCell</span><span class="token punctuation">(</span><span class="token number">190</span><span class="token punctuation">,</span> ht<span class="token punctuation">,</span> <span class="token function">tr</span><span class="token punctuation">(</span>str<span class="token punctuation">)</span><span class="token punctuation">,</span> <span class="token string">""</span><span class="token punctuation">,</span> <span class="token string">"C"</span><span class="token punctuation">,</span> <span class="token boolean">false</span><span class="token punctuation">)</span>
		pdf<span class="token punctuation">.</span><span class="token function">Ln</span><span class="token punctuation">(</span>ht<span class="token punctuation">)</span>
	<span class="token punctuation">&#125;</span>
	pdf<span class="token punctuation">.</span><span class="token function">AddPage</span><span class="token punctuation">(</span><span class="token punctuation">)</span>
	str <span class="token operator">:=</span> <span class="token string">`Gofpdf provides a translator that will convert any UTF-8 code point `</span> <span class="token operator">+</span>
		<span class="token string">`that is present in the specified code page.`</span>
	pdf<span class="token punctuation">.</span><span class="token function">MultiCell</span><span class="token punctuation">(</span><span class="token number">190</span><span class="token punctuation">,</span> ht<span class="token punctuation">,</span> str<span class="token punctuation">,</span> <span class="token string">""</span><span class="token punctuation">,</span> <span class="token string">"L"</span><span class="token punctuation">,</span> <span class="token boolean">false</span><span class="token punctuation">)</span>
	pdf<span class="token punctuation">.</span><span class="token function">Ln</span><span class="token punctuation">(</span><span class="token number">2</span> <span class="token operator">*</span> ht<span class="token punctuation">)</span>
	<span class="token function">write</span><span class="token punctuation">(</span><span class="token string">"Voix ambiguë d'un cœur qui au zéphyr préfère les jattes de kiwi."</span><span class="token punctuation">)</span>
	<span class="token function">write</span><span class="token punctuation">(</span><span class="token string">"Falsches Üben von Xylophonmusik quält jeden größeren Zwerg."</span><span class="token punctuation">)</span>
	<span class="token function">write</span><span class="token punctuation">(</span><span class="token string">"Heizölrückstoßabdämpfung"</span><span class="token punctuation">)</span>
	<span class="token function">write</span><span class="token punctuation">(</span><span class="token string">"Forårsjævndøgn / Efterårsjævndøgn"</span><span class="token punctuation">)</span>
	<span class="token function">write</span><span class="token punctuation">(</span><span class="token string">"À noite, vovô Kowalsky vê o ímã cair no pé do pingüim queixoso e vovó"</span> <span class="token operator">+</span>
		<span class="token string">"põe açúcar no chá de tâmaras do jabuti feliz."</span><span class="token punctuation">)</span>
	pdf<span class="token punctuation">.</span><span class="token function">SetFont</span><span class="token punctuation">(</span><span class="token string">"Helvetica-1251"</span><span class="token punctuation">,</span> <span class="token string">""</span><span class="token punctuation">,</span> fontSize<span class="token punctuation">)</span> <span class="token comment">// Name matches one specified in AddFont()</span>
	tr <span class="token operator">=</span> pdf<span class="token punctuation">.</span><span class="token function">UnicodeTranslatorFromDescriptor</span><span class="token punctuation">(</span><span class="token string">"cp1251"</span><span class="token punctuation">)</span>
	<span class="token function">write</span><span class="token punctuation">(</span><span class="token string">"Съешь же ещё этих мягких французских булок, да выпей чаю."</span><span class="token punctuation">)</span>

	pdf<span class="token punctuation">.</span><span class="token function">SetFont</span><span class="token punctuation">(</span><span class="token string">"Helvetica-1253"</span><span class="token punctuation">,</span> <span class="token string">""</span><span class="token punctuation">,</span> fontSize<span class="token punctuation">)</span>
	tr <span class="token operator">=</span> pdf<span class="token punctuation">.</span><span class="token function">UnicodeTranslatorFromDescriptor</span><span class="token punctuation">(</span><span class="token string">"cp1253"</span><span class="token punctuation">)</span>
	<span class="token function">write</span><span class="token punctuation">(</span><span class="token string">"Θέλει αρετή και τόλμη η ελευθερία. (Ανδρέας Κάλβος)"</span><span class="token punctuation">)</span>

	fileStr <span class="token operator">:=</span> example<span class="token punctuation">.</span><span class="token function">Filename</span><span class="token punctuation">(</span><span class="token string">"Fpdf_CellFormat_codepage"</span><span class="token punctuation">)</span>
	err <span class="token operator">:=</span> pdf<span class="token punctuation">.</span><span class="token function">OutputFileAndClose</span><span class="token punctuation">(</span>fileStr<span class="token punctuation">)</span>
	example<span class="token punctuation">.</span><span class="token function">Summary</span><span class="token punctuation">(</span>err<span class="token punctuation">,</span> fileStr<span class="token punctuation">)</span>
	<span class="token comment">// Output:</span>
	<span class="token comment">// Successfully generated pdf/Fpdf_CellFormat_codepage.pdf</span>
<span class="token punctuation">&#125;</span></code></pre>

<h2 id="演示文档的密码保护"><a href="#演示文档的密码保护" class="headerlink" title="演示文档的密码保护"></a>演示文档的密码保护</h2><pre class="language-go" data-language="go"><code class="language-go"><span class="token comment">// ExampleFpdf_SetProtection demonstrates password protection for documents.</span>
<span class="token keyword">func</span> <span class="token function">ExampleFpdf_SetProtection</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">&#123;</span>
	pdf <span class="token operator">:=</span> gofpdf<span class="token punctuation">.</span><span class="token function">New</span><span class="token punctuation">(</span><span class="token string">"P"</span><span class="token punctuation">,</span> <span class="token string">"mm"</span><span class="token punctuation">,</span> <span class="token string">"A4"</span><span class="token punctuation">,</span> <span class="token string">""</span><span class="token punctuation">)</span>
	pdf<span class="token punctuation">.</span><span class="token function">SetProtection</span><span class="token punctuation">(</span>gofpdf<span class="token punctuation">.</span>CnProtectPrint<span class="token punctuation">,</span> <span class="token string">"123"</span><span class="token punctuation">,</span> <span class="token string">"abc"</span><span class="token punctuation">)</span>
	pdf<span class="token punctuation">.</span><span class="token function">AddPage</span><span class="token punctuation">(</span><span class="token punctuation">)</span>
	pdf<span class="token punctuation">.</span><span class="token function">SetFont</span><span class="token punctuation">(</span><span class="token string">"Arial"</span><span class="token punctuation">,</span> <span class="token string">""</span><span class="token punctuation">,</span> <span class="token number">12</span><span class="token punctuation">)</span>
	pdf<span class="token punctuation">.</span><span class="token function">Write</span><span class="token punctuation">(</span><span class="token number">10</span><span class="token punctuation">,</span> <span class="token string">"Password-protected."</span><span class="token punctuation">)</span>
	fileStr <span class="token operator">:=</span> example<span class="token punctuation">.</span><span class="token function">Filename</span><span class="token punctuation">(</span><span class="token string">"Fpdf_SetProtection"</span><span class="token punctuation">)</span>
	err <span class="token operator">:=</span> pdf<span class="token punctuation">.</span><span class="token function">OutputFileAndClose</span><span class="token punctuation">(</span>fileStr<span class="token punctuation">)</span>
	example<span class="token punctuation">.</span><span class="token function">Summary</span><span class="token punctuation">(</span>err<span class="token punctuation">,</span> fileStr<span class="token punctuation">)</span>
	<span class="token comment">// Output:</span>
	<span class="token comment">// Successfully generated pdf/Fpdf_SetProtection.pdf</span>
<span class="token punctuation">&#125;</span></code></pre>

<h2 id="在多边形函数的演示中显示等边多边形"><a href="#在多边形函数的演示中显示等边多边形" class="headerlink" title="在多边形函数的演示中显示等边多边形"></a>在多边形函数的演示中显示等边多边形</h2><pre class="language-go" data-language="go"><code class="language-go"><span class="token comment">// ExampleFpdf_Polygon displays equilateral polygons in a demonstration of the Polygon</span>
<span class="token comment">// function.</span>
<span class="token keyword">func</span> <span class="token function">ExampleFpdf_Polygon</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">&#123;</span>
	<span class="token keyword">const</span> rowCount <span class="token operator">=</span> <span class="token number">5</span>
	<span class="token keyword">const</span> colCount <span class="token operator">=</span> <span class="token number">4</span>
	<span class="token keyword">const</span> ptSize <span class="token operator">=</span> <span class="token number">36</span>
	<span class="token keyword">var</span> x<span class="token punctuation">,</span> y<span class="token punctuation">,</span> radius<span class="token punctuation">,</span> gap<span class="token punctuation">,</span> advance <span class="token builtin">float64</span>
	<span class="token keyword">var</span> rgVal <span class="token builtin">int</span>
	<span class="token keyword">var</span> pts <span class="token punctuation">[</span><span class="token punctuation">]</span>gofpdf<span class="token punctuation">.</span>PointType
	vertices <span class="token operator">:=</span> <span class="token keyword">func</span><span class="token punctuation">(</span>count <span class="token builtin">int</span><span class="token punctuation">)</span> <span class="token punctuation">(</span>res <span class="token punctuation">[</span><span class="token punctuation">]</span>gofpdf<span class="token punctuation">.</span>PointType<span class="token punctuation">)</span> <span class="token punctuation">&#123;</span>
		<span class="token keyword">var</span> pt gofpdf<span class="token punctuation">.</span>PointType
		res <span class="token operator">=</span> <span class="token function">make</span><span class="token punctuation">(</span><span class="token punctuation">[</span><span class="token punctuation">]</span>gofpdf<span class="token punctuation">.</span>PointType<span class="token punctuation">,</span> <span class="token number">0</span><span class="token punctuation">,</span> count<span class="token punctuation">)</span>
		mlt <span class="token operator">:=</span> <span class="token number">2.0</span> <span class="token operator">*</span> math<span class="token punctuation">.</span>Pi <span class="token operator">/</span> <span class="token function">float64</span><span class="token punctuation">(</span>count<span class="token punctuation">)</span>
		<span class="token keyword">for</span> j <span class="token operator">:=</span> <span class="token number">0</span><span class="token punctuation">;</span> j <span class="token operator">&lt;</span> count<span class="token punctuation">;</span> j<span class="token operator">++</span> <span class="token punctuation">&#123;</span>
			pt<span class="token punctuation">.</span>Y<span class="token punctuation">,</span> pt<span class="token punctuation">.</span>X <span class="token operator">=</span> math<span class="token punctuation">.</span><span class="token function">Sincos</span><span class="token punctuation">(</span><span class="token function">float64</span><span class="token punctuation">(</span>j<span class="token punctuation">)</span> <span class="token operator">*</span> mlt<span class="token punctuation">)</span>
			res <span class="token operator">=</span> <span class="token function">append</span><span class="token punctuation">(</span>res<span class="token punctuation">,</span> gofpdf<span class="token punctuation">.</span>PointType<span class="token punctuation">&#123;</span>
				X<span class="token punctuation">:</span> x <span class="token operator">+</span> radius<span class="token operator">*</span>pt<span class="token punctuation">.</span>X<span class="token punctuation">,</span>
				Y<span class="token punctuation">:</span> y <span class="token operator">+</span> radius<span class="token operator">*</span>pt<span class="token punctuation">.</span>Y<span class="token punctuation">&#125;</span><span class="token punctuation">)</span>
		<span class="token punctuation">&#125;</span>
		<span class="token keyword">return</span>
	<span class="token punctuation">&#125;</span>
	pdf <span class="token operator">:=</span> gofpdf<span class="token punctuation">.</span><span class="token function">New</span><span class="token punctuation">(</span><span class="token string">"P"</span><span class="token punctuation">,</span> <span class="token string">"mm"</span><span class="token punctuation">,</span> <span class="token string">"A4"</span><span class="token punctuation">,</span> <span class="token string">""</span><span class="token punctuation">)</span> <span class="token comment">// A4 210.0 x 297.0</span>
	pdf<span class="token punctuation">.</span><span class="token function">AddPage</span><span class="token punctuation">(</span><span class="token punctuation">)</span>
	pdf<span class="token punctuation">.</span><span class="token function">SetFont</span><span class="token punctuation">(</span><span class="token string">"Helvetica"</span><span class="token punctuation">,</span> <span class="token string">""</span><span class="token punctuation">,</span> ptSize<span class="token punctuation">)</span>
	pdf<span class="token punctuation">.</span><span class="token function">SetDrawColor</span><span class="token punctuation">(</span><span class="token number">0</span><span class="token punctuation">,</span> <span class="token number">80</span><span class="token punctuation">,</span> <span class="token number">180</span><span class="token punctuation">)</span>
	gap <span class="token operator">=</span> <span class="token number">12.0</span>
	pdf<span class="token punctuation">.</span><span class="token function">SetY</span><span class="token punctuation">(</span>gap<span class="token punctuation">)</span>
	pdf<span class="token punctuation">.</span><span class="token function">CellFormat</span><span class="token punctuation">(</span><span class="token number">190.0</span><span class="token punctuation">,</span> gap<span class="token punctuation">,</span> <span class="token string">"Equilateral polygons"</span><span class="token punctuation">,</span> <span class="token string">""</span><span class="token punctuation">,</span> <span class="token number">1</span><span class="token punctuation">,</span> <span class="token string">"C"</span><span class="token punctuation">,</span> <span class="token boolean">false</span><span class="token punctuation">,</span> <span class="token number">0</span><span class="token punctuation">,</span> <span class="token string">""</span><span class="token punctuation">)</span>
	radius <span class="token operator">=</span> <span class="token punctuation">(</span><span class="token number">210.0</span> <span class="token operator">-</span> <span class="token function">float64</span><span class="token punctuation">(</span>colCount<span class="token operator">+</span><span class="token number">1</span><span class="token punctuation">)</span><span class="token operator">*</span>gap<span class="token punctuation">)</span> <span class="token operator">/</span> <span class="token punctuation">(</span><span class="token number">2.0</span> <span class="token operator">*</span> <span class="token function">float64</span><span class="token punctuation">(</span>colCount<span class="token punctuation">)</span><span class="token punctuation">)</span>
	advance <span class="token operator">=</span> gap <span class="token operator">+</span> <span class="token number">2.0</span><span class="token operator">*</span>radius
	y <span class="token operator">=</span> <span class="token number">2</span><span class="token operator">*</span>gap <span class="token operator">+</span> pdf<span class="token punctuation">.</span><span class="token function">PointConvert</span><span class="token punctuation">(</span>ptSize<span class="token punctuation">)</span> <span class="token operator">+</span> radius
	rgVal <span class="token operator">=</span> <span class="token number">230</span>
	<span class="token keyword">for</span> row <span class="token operator">:=</span> <span class="token number">0</span><span class="token punctuation">;</span> row <span class="token operator">&lt;</span> rowCount<span class="token punctuation">;</span> row<span class="token operator">++</span> <span class="token punctuation">&#123;</span>
		pdf<span class="token punctuation">.</span><span class="token function">SetFillColor</span><span class="token punctuation">(</span>rgVal<span class="token punctuation">,</span> rgVal<span class="token punctuation">,</span> <span class="token number">0</span><span class="token punctuation">)</span>
		rgVal <span class="token operator">-=</span> <span class="token number">12</span>
		x <span class="token operator">=</span> gap <span class="token operator">+</span> radius
		<span class="token keyword">for</span> col <span class="token operator">:=</span> <span class="token number">0</span><span class="token punctuation">;</span> col <span class="token operator">&lt;</span> colCount<span class="token punctuation">;</span> col<span class="token operator">++</span> <span class="token punctuation">&#123;</span>
			pts <span class="token operator">=</span> <span class="token function">vertices</span><span class="token punctuation">(</span>row<span class="token operator">*</span>colCount <span class="token operator">+</span> col <span class="token operator">+</span> <span class="token number">3</span><span class="token punctuation">)</span>
			pdf<span class="token punctuation">.</span><span class="token function">Polygon</span><span class="token punctuation">(</span>pts<span class="token punctuation">,</span> <span class="token string">"FD"</span><span class="token punctuation">)</span>
			x <span class="token operator">+=</span> advance
		<span class="token punctuation">&#125;</span>
		y <span class="token operator">+=</span> advance
	<span class="token punctuation">&#125;</span>
	fileStr <span class="token operator">:=</span> example<span class="token punctuation">.</span><span class="token function">Filename</span><span class="token punctuation">(</span><span class="token string">"Fpdf_Polygon"</span><span class="token punctuation">)</span>
	err <span class="token operator">:=</span> pdf<span class="token punctuation">.</span><span class="token function">OutputFileAndClose</span><span class="token punctuation">(</span>fileStr<span class="token punctuation">)</span>
	example<span class="token punctuation">.</span><span class="token function">Summary</span><span class="token punctuation">(</span>err<span class="token punctuation">,</span> fileStr<span class="token punctuation">)</span>
	<span class="token comment">// Output:</span>
	<span class="token comment">// Successfully generated pdf/Fpdf_Polygon.pdf</span>
<span class="token punctuation">&#125;</span></code></pre>

<h2 id="演示文档图层"><a href="#演示文档图层" class="headerlink" title="演示文档图层"></a>演示文档图层</h2><p>图层的初始可见性是用第二个参数AddLayer()指定的。文档阅读器显示的层列表允许交互式地控制层的可见性。</p>
<pre class="language-go" data-language="go"><code class="language-go"><span class="token comment">// ExampleFpdf_AddLayer demonstrates document layers. The initial visibility of a layer</span>
<span class="token comment">// is specified with the second parameter to AddLayer(). The layer list</span>
<span class="token comment">// displayed by the document reader allows layer visibility to be controlled</span>
<span class="token comment">// interactively.</span>
<span class="token keyword">func</span> <span class="token function">ExampleFpdf_AddLayer</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">&#123;</span>

	pdf <span class="token operator">:=</span> gofpdf<span class="token punctuation">.</span><span class="token function">New</span><span class="token punctuation">(</span><span class="token string">"P"</span><span class="token punctuation">,</span> <span class="token string">"mm"</span><span class="token punctuation">,</span> <span class="token string">"A4"</span><span class="token punctuation">,</span> <span class="token string">""</span><span class="token punctuation">)</span>
	pdf<span class="token punctuation">.</span><span class="token function">AddPage</span><span class="token punctuation">(</span><span class="token punctuation">)</span>
	pdf<span class="token punctuation">.</span><span class="token function">SetFont</span><span class="token punctuation">(</span><span class="token string">"Arial"</span><span class="token punctuation">,</span> <span class="token string">""</span><span class="token punctuation">,</span> <span class="token number">15</span><span class="token punctuation">)</span>
	pdf<span class="token punctuation">.</span><span class="token function">Write</span><span class="token punctuation">(</span><span class="token number">8</span><span class="token punctuation">,</span> <span class="token string">"This line doesn't belong to any layer.\n"</span><span class="token punctuation">)</span>

	<span class="token comment">// Define layers</span>
	l1 <span class="token operator">:=</span> pdf<span class="token punctuation">.</span><span class="token function">AddLayer</span><span class="token punctuation">(</span><span class="token string">"Layer 1"</span><span class="token punctuation">,</span> <span class="token boolean">true</span><span class="token punctuation">)</span>
	l2 <span class="token operator">:=</span> pdf<span class="token punctuation">.</span><span class="token function">AddLayer</span><span class="token punctuation">(</span><span class="token string">"Layer 2"</span><span class="token punctuation">,</span> <span class="token boolean">true</span><span class="token punctuation">)</span>

	<span class="token comment">// Open layer pane in PDF viewer</span>
	pdf<span class="token punctuation">.</span><span class="token function">OpenLayerPane</span><span class="token punctuation">(</span><span class="token punctuation">)</span>

	<span class="token comment">// First layer</span>
	pdf<span class="token punctuation">.</span><span class="token function">BeginLayer</span><span class="token punctuation">(</span>l1<span class="token punctuation">)</span>
	pdf<span class="token punctuation">.</span><span class="token function">Write</span><span class="token punctuation">(</span><span class="token number">8</span><span class="token punctuation">,</span> <span class="token string">"This line belongs to layer 1.\n"</span><span class="token punctuation">)</span>
	pdf<span class="token punctuation">.</span><span class="token function">EndLayer</span><span class="token punctuation">(</span><span class="token punctuation">)</span>

	<span class="token comment">// Second layer</span>
	pdf<span class="token punctuation">.</span><span class="token function">BeginLayer</span><span class="token punctuation">(</span>l2<span class="token punctuation">)</span>
	pdf<span class="token punctuation">.</span><span class="token function">Write</span><span class="token punctuation">(</span><span class="token number">8</span><span class="token punctuation">,</span> <span class="token string">"This line belongs to layer 2.\n"</span><span class="token punctuation">)</span>
	pdf<span class="token punctuation">.</span><span class="token function">EndLayer</span><span class="token punctuation">(</span><span class="token punctuation">)</span>

	<span class="token comment">// First layer again</span>
	pdf<span class="token punctuation">.</span><span class="token function">BeginLayer</span><span class="token punctuation">(</span>l1<span class="token punctuation">)</span>
	pdf<span class="token punctuation">.</span><span class="token function">Write</span><span class="token punctuation">(</span><span class="token number">8</span><span class="token punctuation">,</span> <span class="token string">"This line belongs to layer 1 again.\n"</span><span class="token punctuation">)</span>
	pdf<span class="token punctuation">.</span><span class="token function">EndLayer</span><span class="token punctuation">(</span><span class="token punctuation">)</span>

	fileStr <span class="token operator">:=</span> example<span class="token punctuation">.</span><span class="token function">Filename</span><span class="token punctuation">(</span><span class="token string">"Fpdf_AddLayer"</span><span class="token punctuation">)</span>
	err <span class="token operator">:=</span> pdf<span class="token punctuation">.</span><span class="token function">OutputFileAndClose</span><span class="token punctuation">(</span>fileStr<span class="token punctuation">)</span>
	example<span class="token punctuation">.</span><span class="token function">Summary</span><span class="token punctuation">(</span>err<span class="token punctuation">,</span> fileStr<span class="token punctuation">)</span>
	<span class="token comment">// Output:</span>
	<span class="token comment">// Successfully generated pdf/Fpdf_AddLayer.pdf</span>
<span class="token punctuation">&#125;</span></code></pre>

<h2 id="演示如何使用从web服务器检索到的图像"><a href="#演示如何使用从web服务器检索到的图像" class="headerlink" title="演示如何使用从web服务器检索到的图像"></a>演示如何使用从web服务器检索到的图像</h2><pre class="language-go" data-language="go"><code class="language-go"><span class="token comment">// ExampleFpdf_RegisterImageReader demonstrates the use of an image that is retrieved from a web</span>
<span class="token comment">// server.</span>
<span class="token keyword">func</span> <span class="token function">ExampleFpdf_RegisterImageReader</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">&#123;</span>

	<span class="token keyword">const</span> <span class="token punctuation">(</span>
		margin   <span class="token operator">=</span> <span class="token number">10</span>
		wd       <span class="token operator">=</span> <span class="token number">210</span>
		ht       <span class="token operator">=</span> <span class="token number">297</span>
		fontSize <span class="token operator">=</span> <span class="token number">15</span>
		urlStr   <span class="token operator">=</span> <span class="token string">"https://github.com/jung-kurt/gofpdf/blob/master/image/gofpdf.png?raw=true"</span>
		msgStr   <span class="token operator">=</span> <span class="token string">`Images from the web can be easily embedded when a PDF document is generated.`</span>
	<span class="token punctuation">)</span>

	<span class="token keyword">var</span> <span class="token punctuation">(</span>
		rsp <span class="token operator">*</span>http<span class="token punctuation">.</span>Response
		err <span class="token builtin">error</span>
		tp  <span class="token builtin">string</span>
	<span class="token punctuation">)</span>

	pdf <span class="token operator">:=</span> gofpdf<span class="token punctuation">.</span><span class="token function">New</span><span class="token punctuation">(</span><span class="token string">"P"</span><span class="token punctuation">,</span> <span class="token string">"mm"</span><span class="token punctuation">,</span> <span class="token string">"A4"</span><span class="token punctuation">,</span> <span class="token string">""</span><span class="token punctuation">)</span>
	pdf<span class="token punctuation">.</span><span class="token function">AddPage</span><span class="token punctuation">(</span><span class="token punctuation">)</span>
	pdf<span class="token punctuation">.</span><span class="token function">SetFont</span><span class="token punctuation">(</span><span class="token string">"Helvetica"</span><span class="token punctuation">,</span> <span class="token string">""</span><span class="token punctuation">,</span> fontSize<span class="token punctuation">)</span>
	ln <span class="token operator">:=</span> pdf<span class="token punctuation">.</span><span class="token function">PointConvert</span><span class="token punctuation">(</span>fontSize<span class="token punctuation">)</span>
	pdf<span class="token punctuation">.</span><span class="token function">MultiCell</span><span class="token punctuation">(</span>wd<span class="token operator">-</span>margin<span class="token operator">-</span>margin<span class="token punctuation">,</span> ln<span class="token punctuation">,</span> msgStr<span class="token punctuation">,</span> <span class="token string">""</span><span class="token punctuation">,</span> <span class="token string">"L"</span><span class="token punctuation">,</span> <span class="token boolean">false</span><span class="token punctuation">)</span>
	rsp<span class="token punctuation">,</span> err <span class="token operator">=</span> http<span class="token punctuation">.</span><span class="token function">Get</span><span class="token punctuation">(</span>urlStr<span class="token punctuation">)</span>
	<span class="token keyword">if</span> err <span class="token operator">==</span> <span class="token boolean">nil</span> <span class="token punctuation">&#123;</span>
		tp <span class="token operator">=</span> pdf<span class="token punctuation">.</span><span class="token function">ImageTypeFromMime</span><span class="token punctuation">(</span>rsp<span class="token punctuation">.</span>Header<span class="token punctuation">[</span><span class="token string">"Content-Type"</span><span class="token punctuation">]</span><span class="token punctuation">[</span><span class="token number">0</span><span class="token punctuation">]</span><span class="token punctuation">)</span>
		infoPtr <span class="token operator">:=</span> pdf<span class="token punctuation">.</span><span class="token function">RegisterImageReader</span><span class="token punctuation">(</span>urlStr<span class="token punctuation">,</span> tp<span class="token punctuation">,</span> rsp<span class="token punctuation">.</span>Body<span class="token punctuation">)</span>
		<span class="token keyword">if</span> pdf<span class="token punctuation">.</span><span class="token function">Ok</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">&#123;</span>
			imgWd<span class="token punctuation">,</span> imgHt <span class="token operator">:=</span> infoPtr<span class="token punctuation">.</span><span class="token function">Extent</span><span class="token punctuation">(</span><span class="token punctuation">)</span>
			pdf<span class="token punctuation">.</span><span class="token function">Image</span><span class="token punctuation">(</span>urlStr<span class="token punctuation">,</span> <span class="token punctuation">(</span>wd<span class="token operator">-</span>imgWd<span class="token punctuation">)</span><span class="token operator">/</span><span class="token number">2.0</span><span class="token punctuation">,</span> pdf<span class="token punctuation">.</span><span class="token function">GetY</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token operator">+</span>ln<span class="token punctuation">,</span>
				imgWd<span class="token punctuation">,</span> imgHt<span class="token punctuation">,</span> <span class="token boolean">false</span><span class="token punctuation">,</span> tp<span class="token punctuation">,</span> <span class="token number">0</span><span class="token punctuation">,</span> <span class="token string">""</span><span class="token punctuation">)</span>
		<span class="token punctuation">&#125;</span>
	<span class="token punctuation">&#125;</span> <span class="token keyword">else</span> <span class="token punctuation">&#123;</span>
		pdf<span class="token punctuation">.</span><span class="token function">SetError</span><span class="token punctuation">(</span>err<span class="token punctuation">)</span>
	<span class="token punctuation">&#125;</span>
	fileStr <span class="token operator">:=</span> example<span class="token punctuation">.</span><span class="token function">Filename</span><span class="token punctuation">(</span><span class="token string">"Fpdf_RegisterImageReader_url"</span><span class="token punctuation">)</span>
	err <span class="token operator">=</span> pdf<span class="token punctuation">.</span><span class="token function">OutputFileAndClose</span><span class="token punctuation">(</span>fileStr<span class="token punctuation">)</span>
	example<span class="token punctuation">.</span><span class="token function">Summary</span><span class="token punctuation">(</span>err<span class="token punctuation">,</span> fileStr<span class="token punctuation">)</span>
	<span class="token comment">// Output:</span>
	<span class="token comment">// Successfully generated pdf/Fpdf_RegisterImageReader_url.pdf</span>

<span class="token punctuation">&#125;</span></code></pre>

<h2 id="演示Beziergon函数"><a href="#演示Beziergon函数" class="headerlink" title="演示Beziergon函数"></a>演示Beziergon函数</h2><pre class="language-go" data-language="go"><code class="language-go"><span class="token comment">// ExampleFpdf_Beziergon demonstrates the Beziergon function.</span>
<span class="token keyword">func</span> <span class="token function">ExampleFpdf_Beziergon</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">&#123;</span>

	<span class="token keyword">const</span> <span class="token punctuation">(</span>
		margin      <span class="token operator">=</span> <span class="token number">10</span>
		wd          <span class="token operator">=</span> <span class="token number">210</span>
		unit        <span class="token operator">=</span> <span class="token punctuation">(</span>wd <span class="token operator">-</span> <span class="token number">2</span><span class="token operator">*</span>margin<span class="token punctuation">)</span> <span class="token operator">/</span> <span class="token number">6</span>
		ht          <span class="token operator">=</span> <span class="token number">297</span>
		fontSize    <span class="token operator">=</span> <span class="token number">15</span>
		msgStr      <span class="token operator">=</span> <span class="token string">`Demonstration of Beziergon function`</span>
		coefficient <span class="token operator">=</span> <span class="token number">0.6</span>
		delta       <span class="token operator">=</span> coefficient <span class="token operator">*</span> unit
		ln          <span class="token operator">=</span> fontSize <span class="token operator">*</span> <span class="token number">25.4</span> <span class="token operator">/</span> <span class="token number">72</span>
		offsetX     <span class="token operator">=</span> <span class="token punctuation">(</span>wd <span class="token operator">-</span> <span class="token number">4</span><span class="token operator">*</span>unit<span class="token punctuation">)</span> <span class="token operator">/</span> <span class="token number">2.0</span>
		offsetY     <span class="token operator">=</span> offsetX <span class="token operator">+</span> <span class="token number">2</span><span class="token operator">*</span>ln
	<span class="token punctuation">)</span>

	srcList <span class="token operator">:=</span> <span class="token punctuation">[</span><span class="token punctuation">]</span>gofpdf<span class="token punctuation">.</span>PointType<span class="token punctuation">&#123;</span>
		<span class="token punctuation">&#123;</span>X<span class="token punctuation">:</span> <span class="token number">0</span><span class="token punctuation">,</span> Y<span class="token punctuation">:</span> <span class="token number">0</span><span class="token punctuation">&#125;</span><span class="token punctuation">,</span>
		<span class="token punctuation">&#123;</span>X<span class="token punctuation">:</span> <span class="token number">1</span><span class="token punctuation">,</span> Y<span class="token punctuation">:</span> <span class="token number">0</span><span class="token punctuation">&#125;</span><span class="token punctuation">,</span>
		<span class="token punctuation">&#123;</span>X<span class="token punctuation">:</span> <span class="token number">1</span><span class="token punctuation">,</span> Y<span class="token punctuation">:</span> <span class="token number">1</span><span class="token punctuation">&#125;</span><span class="token punctuation">,</span>
		<span class="token punctuation">&#123;</span>X<span class="token punctuation">:</span> <span class="token number">2</span><span class="token punctuation">,</span> Y<span class="token punctuation">:</span> <span class="token number">1</span><span class="token punctuation">&#125;</span><span class="token punctuation">,</span>
		<span class="token punctuation">&#123;</span>X<span class="token punctuation">:</span> <span class="token number">2</span><span class="token punctuation">,</span> Y<span class="token punctuation">:</span> <span class="token number">2</span><span class="token punctuation">&#125;</span><span class="token punctuation">,</span>
		<span class="token punctuation">&#123;</span>X<span class="token punctuation">:</span> <span class="token number">3</span><span class="token punctuation">,</span> Y<span class="token punctuation">:</span> <span class="token number">2</span><span class="token punctuation">&#125;</span><span class="token punctuation">,</span>
		<span class="token punctuation">&#123;</span>X<span class="token punctuation">:</span> <span class="token number">3</span><span class="token punctuation">,</span> Y<span class="token punctuation">:</span> <span class="token number">3</span><span class="token punctuation">&#125;</span><span class="token punctuation">,</span>
		<span class="token punctuation">&#123;</span>X<span class="token punctuation">:</span> <span class="token number">4</span><span class="token punctuation">,</span> Y<span class="token punctuation">:</span> <span class="token number">3</span><span class="token punctuation">&#125;</span><span class="token punctuation">,</span>
		<span class="token punctuation">&#123;</span>X<span class="token punctuation">:</span> <span class="token number">4</span><span class="token punctuation">,</span> Y<span class="token punctuation">:</span> <span class="token number">4</span><span class="token punctuation">&#125;</span><span class="token punctuation">,</span>
		<span class="token punctuation">&#123;</span>X<span class="token punctuation">:</span> <span class="token number">1</span><span class="token punctuation">,</span> Y<span class="token punctuation">:</span> <span class="token number">4</span><span class="token punctuation">&#125;</span><span class="token punctuation">,</span>
		<span class="token punctuation">&#123;</span>X<span class="token punctuation">:</span> <span class="token number">1</span><span class="token punctuation">,</span> Y<span class="token punctuation">:</span> <span class="token number">3</span><span class="token punctuation">&#125;</span><span class="token punctuation">,</span>
		<span class="token punctuation">&#123;</span>X<span class="token punctuation">:</span> <span class="token number">0</span><span class="token punctuation">,</span> Y<span class="token punctuation">:</span> <span class="token number">3</span><span class="token punctuation">&#125;</span><span class="token punctuation">,</span>
	<span class="token punctuation">&#125;</span>

	ctrlList <span class="token operator">:=</span> <span class="token punctuation">[</span><span class="token punctuation">]</span>gofpdf<span class="token punctuation">.</span>PointType<span class="token punctuation">&#123;</span>
		<span class="token punctuation">&#123;</span>X<span class="token punctuation">:</span> <span class="token number">1</span><span class="token punctuation">,</span> Y<span class="token punctuation">:</span> <span class="token operator">-</span><span class="token number">1</span><span class="token punctuation">&#125;</span><span class="token punctuation">,</span>
		<span class="token punctuation">&#123;</span>X<span class="token punctuation">:</span> <span class="token number">1</span><span class="token punctuation">,</span> Y<span class="token punctuation">:</span> <span class="token number">1</span><span class="token punctuation">&#125;</span><span class="token punctuation">,</span>
		<span class="token punctuation">&#123;</span>X<span class="token punctuation">:</span> <span class="token number">1</span><span class="token punctuation">,</span> Y<span class="token punctuation">:</span> <span class="token number">1</span><span class="token punctuation">&#125;</span><span class="token punctuation">,</span>
		<span class="token punctuation">&#123;</span>X<span class="token punctuation">:</span> <span class="token number">1</span><span class="token punctuation">,</span> Y<span class="token punctuation">:</span> <span class="token number">1</span><span class="token punctuation">&#125;</span><span class="token punctuation">,</span>
		<span class="token punctuation">&#123;</span>X<span class="token punctuation">:</span> <span class="token number">1</span><span class="token punctuation">,</span> Y<span class="token punctuation">:</span> <span class="token number">1</span><span class="token punctuation">&#125;</span><span class="token punctuation">,</span>
		<span class="token punctuation">&#123;</span>X<span class="token punctuation">:</span> <span class="token number">1</span><span class="token punctuation">,</span> Y<span class="token punctuation">:</span> <span class="token number">1</span><span class="token punctuation">&#125;</span><span class="token punctuation">,</span>
		<span class="token punctuation">&#123;</span>X<span class="token punctuation">:</span> <span class="token number">1</span><span class="token punctuation">,</span> Y<span class="token punctuation">:</span> <span class="token number">1</span><span class="token punctuation">&#125;</span><span class="token punctuation">,</span>
		<span class="token punctuation">&#123;</span>X<span class="token punctuation">:</span> <span class="token number">1</span><span class="token punctuation">,</span> Y<span class="token punctuation">:</span> <span class="token number">1</span><span class="token punctuation">&#125;</span><span class="token punctuation">,</span>
		<span class="token punctuation">&#123;</span>X<span class="token punctuation">:</span> <span class="token operator">-</span><span class="token number">1</span><span class="token punctuation">,</span> Y<span class="token punctuation">:</span> <span class="token number">1</span><span class="token punctuation">&#125;</span><span class="token punctuation">,</span>
		<span class="token punctuation">&#123;</span>X<span class="token punctuation">:</span> <span class="token operator">-</span><span class="token number">1</span><span class="token punctuation">,</span> Y<span class="token punctuation">:</span> <span class="token operator">-</span><span class="token number">1</span><span class="token punctuation">&#125;</span><span class="token punctuation">,</span>
		<span class="token punctuation">&#123;</span>X<span class="token punctuation">:</span> <span class="token operator">-</span><span class="token number">1</span><span class="token punctuation">,</span> Y<span class="token punctuation">:</span> <span class="token operator">-</span><span class="token number">1</span><span class="token punctuation">&#125;</span><span class="token punctuation">,</span>
		<span class="token punctuation">&#123;</span>X<span class="token punctuation">:</span> <span class="token operator">-</span><span class="token number">1</span><span class="token punctuation">,</span> Y<span class="token punctuation">:</span> <span class="token operator">-</span><span class="token number">1</span><span class="token punctuation">&#125;</span><span class="token punctuation">,</span>
	<span class="token punctuation">&#125;</span>

	pdf <span class="token operator">:=</span> gofpdf<span class="token punctuation">.</span><span class="token function">New</span><span class="token punctuation">(</span><span class="token string">"P"</span><span class="token punctuation">,</span> <span class="token string">"mm"</span><span class="token punctuation">,</span> <span class="token string">"A4"</span><span class="token punctuation">,</span> <span class="token string">""</span><span class="token punctuation">)</span>
	pdf<span class="token punctuation">.</span><span class="token function">AddPage</span><span class="token punctuation">(</span><span class="token punctuation">)</span>
	pdf<span class="token punctuation">.</span><span class="token function">SetFont</span><span class="token punctuation">(</span><span class="token string">"Helvetica"</span><span class="token punctuation">,</span> <span class="token string">""</span><span class="token punctuation">,</span> fontSize<span class="token punctuation">)</span>
	<span class="token keyword">for</span> j<span class="token punctuation">,</span> src <span class="token operator">:=</span> <span class="token keyword">range</span> srcList <span class="token punctuation">&#123;</span>
		srcList<span class="token punctuation">[</span>j<span class="token punctuation">]</span><span class="token punctuation">.</span>X <span class="token operator">=</span> offsetX <span class="token operator">+</span> src<span class="token punctuation">.</span>X<span class="token operator">*</span>unit
		srcList<span class="token punctuation">[</span>j<span class="token punctuation">]</span><span class="token punctuation">.</span>Y <span class="token operator">=</span> offsetY <span class="token operator">+</span> src<span class="token punctuation">.</span>Y<span class="token operator">*</span>unit
	<span class="token punctuation">&#125;</span>
	<span class="token keyword">for</span> j<span class="token punctuation">,</span> ctrl <span class="token operator">:=</span> <span class="token keyword">range</span> ctrlList <span class="token punctuation">&#123;</span>
		ctrlList<span class="token punctuation">[</span>j<span class="token punctuation">]</span><span class="token punctuation">.</span>X <span class="token operator">=</span> ctrl<span class="token punctuation">.</span>X <span class="token operator">*</span> delta
		ctrlList<span class="token punctuation">[</span>j<span class="token punctuation">]</span><span class="token punctuation">.</span>Y <span class="token operator">=</span> ctrl<span class="token punctuation">.</span>Y <span class="token operator">*</span> delta
	<span class="token punctuation">&#125;</span>
	jPrev <span class="token operator">:=</span> <span class="token function">len</span><span class="token punctuation">(</span>srcList<span class="token punctuation">)</span> <span class="token operator">-</span> <span class="token number">1</span>
	srcPrev <span class="token operator">:=</span> srcList<span class="token punctuation">[</span>jPrev<span class="token punctuation">]</span>
	curveList <span class="token operator">:=</span> <span class="token punctuation">[</span><span class="token punctuation">]</span>gofpdf<span class="token punctuation">.</span>PointType<span class="token punctuation">&#123;</span>srcPrev<span class="token punctuation">&#125;</span> <span class="token comment">// point [, control 0, control 1, point]*</span>
	control <span class="token operator">:=</span> <span class="token keyword">func</span><span class="token punctuation">(</span>x<span class="token punctuation">,</span> y <span class="token builtin">float64</span><span class="token punctuation">)</span> <span class="token punctuation">&#123;</span>
		curveList <span class="token operator">=</span> <span class="token function">append</span><span class="token punctuation">(</span>curveList<span class="token punctuation">,</span> gofpdf<span class="token punctuation">.</span>PointType<span class="token punctuation">&#123;</span>X<span class="token punctuation">:</span> x<span class="token punctuation">,</span> Y<span class="token punctuation">:</span> y<span class="token punctuation">&#125;</span><span class="token punctuation">)</span>
	<span class="token punctuation">&#125;</span>
	<span class="token keyword">for</span> j<span class="token punctuation">,</span> src <span class="token operator">:=</span> <span class="token keyword">range</span> srcList <span class="token punctuation">&#123;</span>
		ctrl <span class="token operator">:=</span> ctrlList<span class="token punctuation">[</span>jPrev<span class="token punctuation">]</span>
		<span class="token function">control</span><span class="token punctuation">(</span>srcPrev<span class="token punctuation">.</span>X<span class="token operator">+</span>ctrl<span class="token punctuation">.</span>X<span class="token punctuation">,</span> srcPrev<span class="token punctuation">.</span>Y<span class="token operator">+</span>ctrl<span class="token punctuation">.</span>Y<span class="token punctuation">)</span> <span class="token comment">// Control 0</span>
		ctrl <span class="token operator">=</span> ctrlList<span class="token punctuation">[</span>j<span class="token punctuation">]</span>
		<span class="token function">control</span><span class="token punctuation">(</span>src<span class="token punctuation">.</span>X<span class="token operator">-</span>ctrl<span class="token punctuation">.</span>X<span class="token punctuation">,</span> src<span class="token punctuation">.</span>Y<span class="token operator">-</span>ctrl<span class="token punctuation">.</span>Y<span class="token punctuation">)</span> <span class="token comment">// Control 1</span>
		curveList <span class="token operator">=</span> <span class="token function">append</span><span class="token punctuation">(</span>curveList<span class="token punctuation">,</span> src<span class="token punctuation">)</span>  <span class="token comment">// Destination</span>
		jPrev <span class="token operator">=</span> j
		srcPrev <span class="token operator">=</span> src
	<span class="token punctuation">&#125;</span>
	pdf<span class="token punctuation">.</span><span class="token function">MultiCell</span><span class="token punctuation">(</span>wd<span class="token operator">-</span>margin<span class="token operator">-</span>margin<span class="token punctuation">,</span> ln<span class="token punctuation">,</span> msgStr<span class="token punctuation">,</span> <span class="token string">""</span><span class="token punctuation">,</span> <span class="token string">"C"</span><span class="token punctuation">,</span> <span class="token boolean">false</span><span class="token punctuation">)</span>
	pdf<span class="token punctuation">.</span><span class="token function">SetDashPattern</span><span class="token punctuation">(</span><span class="token punctuation">[</span><span class="token punctuation">]</span><span class="token builtin">float64</span><span class="token punctuation">&#123;</span><span class="token number">0.8</span><span class="token punctuation">,</span> <span class="token number">0.8</span><span class="token punctuation">&#125;</span><span class="token punctuation">,</span> <span class="token number">0</span><span class="token punctuation">)</span>
	pdf<span class="token punctuation">.</span><span class="token function">SetDrawColor</span><span class="token punctuation">(</span><span class="token number">160</span><span class="token punctuation">,</span> <span class="token number">160</span><span class="token punctuation">,</span> <span class="token number">160</span><span class="token punctuation">)</span>
	pdf<span class="token punctuation">.</span><span class="token function">Polygon</span><span class="token punctuation">(</span>srcList<span class="token punctuation">,</span> <span class="token string">"D"</span><span class="token punctuation">)</span>
	pdf<span class="token punctuation">.</span><span class="token function">SetDashPattern</span><span class="token punctuation">(</span><span class="token punctuation">[</span><span class="token punctuation">]</span><span class="token builtin">float64</span><span class="token punctuation">&#123;</span><span class="token punctuation">&#125;</span><span class="token punctuation">,</span> <span class="token number">0</span><span class="token punctuation">)</span>
	pdf<span class="token punctuation">.</span><span class="token function">SetDrawColor</span><span class="token punctuation">(</span><span class="token number">64</span><span class="token punctuation">,</span> <span class="token number">64</span><span class="token punctuation">,</span> <span class="token number">128</span><span class="token punctuation">)</span>
	pdf<span class="token punctuation">.</span><span class="token function">SetLineWidth</span><span class="token punctuation">(</span>pdf<span class="token punctuation">.</span><span class="token function">GetLineWidth</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token operator">*</span> <span class="token number">3</span><span class="token punctuation">)</span>
	pdf<span class="token punctuation">.</span><span class="token function">Beziergon</span><span class="token punctuation">(</span>curveList<span class="token punctuation">,</span> <span class="token string">"D"</span><span class="token punctuation">)</span>
	fileStr <span class="token operator">:=</span> example<span class="token punctuation">.</span><span class="token function">Filename</span><span class="token punctuation">(</span><span class="token string">"Fpdf_Beziergon"</span><span class="token punctuation">)</span>
	err <span class="token operator">:=</span> pdf<span class="token punctuation">.</span><span class="token function">OutputFileAndClose</span><span class="token punctuation">(</span>fileStr<span class="token punctuation">)</span>
	example<span class="token punctuation">.</span><span class="token function">Summary</span><span class="token punctuation">(</span>err<span class="token punctuation">,</span> fileStr<span class="token punctuation">)</span>
	<span class="token comment">// Output:</span>
	<span class="token comment">// Successfully generated pdf/Fpdf_Beziergon.pdf</span>

<span class="token punctuation">&#125;</span></code></pre>

<h2 id="演示使用通用字体加载器加载非标准字体"><a href="#演示使用通用字体加载器加载非标准字体" class="headerlink" title="演示使用通用字体加载器加载非标准字体"></a>演示使用通用字体加载器加载非标准字体</h2><p>fontResourceType实现了FontLoader接口，并在测试源代码中进行了本地定义。</p>
<pre class="language-go" data-language="go"><code class="language-go"><span class="token comment">// ExampleFpdf_SetFontLoader demonstrates loading a non-standard font using a generalized</span>
<span class="token comment">// font loader. fontResourceType implements the FontLoader interface and is</span>
<span class="token comment">// defined locally in the test source code.</span>
<span class="token keyword">func</span> <span class="token function">ExampleFpdf_SetFontLoader</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">&#123;</span>
	<span class="token keyword">var</span> fr fontResourceType
	pdf <span class="token operator">:=</span> gofpdf<span class="token punctuation">.</span><span class="token function">New</span><span class="token punctuation">(</span><span class="token string">"P"</span><span class="token punctuation">,</span> <span class="token string">"mm"</span><span class="token punctuation">,</span> <span class="token string">"A4"</span><span class="token punctuation">,</span> <span class="token string">""</span><span class="token punctuation">)</span>
	pdf<span class="token punctuation">.</span><span class="token function">SetFontLoader</span><span class="token punctuation">(</span>fr<span class="token punctuation">)</span>
	pdf<span class="token punctuation">.</span><span class="token function">AddFont</span><span class="token punctuation">(</span><span class="token string">"Calligrapher"</span><span class="token punctuation">,</span> <span class="token string">""</span><span class="token punctuation">,</span> <span class="token string">"calligra.json"</span><span class="token punctuation">)</span>
	pdf<span class="token punctuation">.</span><span class="token function">AddPage</span><span class="token punctuation">(</span><span class="token punctuation">)</span>
	pdf<span class="token punctuation">.</span><span class="token function">SetFont</span><span class="token punctuation">(</span><span class="token string">"Calligrapher"</span><span class="token punctuation">,</span> <span class="token string">""</span><span class="token punctuation">,</span> <span class="token number">35</span><span class="token punctuation">)</span>
	pdf<span class="token punctuation">.</span><span class="token function">Cell</span><span class="token punctuation">(</span><span class="token number">0</span><span class="token punctuation">,</span> <span class="token number">10</span><span class="token punctuation">,</span> <span class="token string">"Load fonts from any source"</span><span class="token punctuation">)</span>
	fileStr <span class="token operator">:=</span> example<span class="token punctuation">.</span><span class="token function">Filename</span><span class="token punctuation">(</span><span class="token string">"Fpdf_SetFontLoader"</span><span class="token punctuation">)</span>
	err <span class="token operator">:=</span> pdf<span class="token punctuation">.</span><span class="token function">OutputFileAndClose</span><span class="token punctuation">(</span>fileStr<span class="token punctuation">)</span>
	example<span class="token punctuation">.</span><span class="token function">Summary</span><span class="token punctuation">(</span>err<span class="token punctuation">,</span> fileStr<span class="token punctuation">)</span>
	<span class="token comment">// Output:</span>
	<span class="token comment">// Generalized font loader reading calligra.json</span>
	<span class="token comment">// Generalized font loader reading calligra.z</span>
	<span class="token comment">// Successfully generated pdf/Fpdf_SetFontLoader.pdf</span>
<span class="token punctuation">&#125;</span></code></pre>

<h2 id="演示路径绘制功能"><a href="#演示路径绘制功能" class="headerlink" title="演示路径绘制功能"></a>演示路径绘制功能</h2><p>如:移动，直线，曲线，…、ClosePath和DrawPath。</p>
<pre class="language-go" data-language="go"><code class="language-go"><span class="token comment">// ExampleFpdf_MoveTo demonstrates the Path Drawing functions, such as: MoveTo,</span>
<span class="token comment">// LineTo, CurveTo, ..., ClosePath and DrawPath.</span>
<span class="token keyword">func</span> <span class="token function">ExampleFpdf_MoveTo</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">&#123;</span>
	pdf <span class="token operator">:=</span> gofpdf<span class="token punctuation">.</span><span class="token function">New</span><span class="token punctuation">(</span><span class="token string">"P"</span><span class="token punctuation">,</span> <span class="token string">"mm"</span><span class="token punctuation">,</span> <span class="token string">"A4"</span><span class="token punctuation">,</span> <span class="token string">""</span><span class="token punctuation">)</span>
	pdf<span class="token punctuation">.</span><span class="token function">AddPage</span><span class="token punctuation">(</span><span class="token punctuation">)</span>
	pdf<span class="token punctuation">.</span><span class="token function">MoveTo</span><span class="token punctuation">(</span><span class="token number">20</span><span class="token punctuation">,</span> <span class="token number">20</span><span class="token punctuation">)</span>
	pdf<span class="token punctuation">.</span><span class="token function">LineTo</span><span class="token punctuation">(</span><span class="token number">170</span><span class="token punctuation">,</span> <span class="token number">20</span><span class="token punctuation">)</span>
	pdf<span class="token punctuation">.</span><span class="token function">ArcTo</span><span class="token punctuation">(</span><span class="token number">170</span><span class="token punctuation">,</span> <span class="token number">40</span><span class="token punctuation">,</span> <span class="token number">20</span><span class="token punctuation">,</span> <span class="token number">20</span><span class="token punctuation">,</span> <span class="token number">0</span><span class="token punctuation">,</span> <span class="token number">90</span><span class="token punctuation">,</span> <span class="token number">0</span><span class="token punctuation">)</span>
	pdf<span class="token punctuation">.</span><span class="token function">CurveTo</span><span class="token punctuation">(</span><span class="token number">190</span><span class="token punctuation">,</span> <span class="token number">100</span><span class="token punctuation">,</span> <span class="token number">105</span><span class="token punctuation">,</span> <span class="token number">100</span><span class="token punctuation">)</span>
	pdf<span class="token punctuation">.</span><span class="token function">CurveBezierCubicTo</span><span class="token punctuation">(</span><span class="token number">20</span><span class="token punctuation">,</span> <span class="token number">100</span><span class="token punctuation">,</span> <span class="token number">105</span><span class="token punctuation">,</span> <span class="token number">200</span><span class="token punctuation">,</span> <span class="token number">20</span><span class="token punctuation">,</span> <span class="token number">200</span><span class="token punctuation">)</span>
	pdf<span class="token punctuation">.</span><span class="token function">ClosePath</span><span class="token punctuation">(</span><span class="token punctuation">)</span>
	pdf<span class="token punctuation">.</span><span class="token function">SetFillColor</span><span class="token punctuation">(</span><span class="token number">200</span><span class="token punctuation">,</span> <span class="token number">200</span><span class="token punctuation">,</span> <span class="token number">200</span><span class="token punctuation">)</span>
	pdf<span class="token punctuation">.</span><span class="token function">SetLineWidth</span><span class="token punctuation">(</span><span class="token number">3</span><span class="token punctuation">)</span>
	pdf<span class="token punctuation">.</span><span class="token function">DrawPath</span><span class="token punctuation">(</span><span class="token string">"DF"</span><span class="token punctuation">)</span>
	fileStr <span class="token operator">:=</span> example<span class="token punctuation">.</span><span class="token function">Filename</span><span class="token punctuation">(</span><span class="token string">"Fpdf_MoveTo_path"</span><span class="token punctuation">)</span>
	err <span class="token operator">:=</span> pdf<span class="token punctuation">.</span><span class="token function">OutputFileAndClose</span><span class="token punctuation">(</span>fileStr<span class="token punctuation">)</span>
	example<span class="token punctuation">.</span><span class="token function">Summary</span><span class="token punctuation">(</span>err<span class="token punctuation">,</span> fileStr<span class="token punctuation">)</span>
	<span class="token comment">// Output:</span>
	<span class="token comment">// Successfully generated pdf/Fpdf_MoveTo_path.pdf</span>
<span class="token punctuation">&#125;</span></code></pre>

<h2 id="演示各种线帽和线连接样式"><a href="#演示各种线帽和线连接样式" class="headerlink" title="演示各种线帽和线连接样式"></a>演示各种线帽和线连接样式</h2><pre class="language-go" data-language="go"><code class="language-go"><span class="token comment">// ExampleFpdf_SetLineJoinStyle demonstrates various line cap and line join styles.</span>
<span class="token keyword">func</span> <span class="token function">ExampleFpdf_SetLineJoinStyle</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">&#123;</span>
	<span class="token keyword">const</span> offset <span class="token operator">=</span> <span class="token number">75.0</span>
	pdf <span class="token operator">:=</span> gofpdf<span class="token punctuation">.</span><span class="token function">New</span><span class="token punctuation">(</span><span class="token string">"L"</span><span class="token punctuation">,</span> <span class="token string">"mm"</span><span class="token punctuation">,</span> <span class="token string">"A4"</span><span class="token punctuation">,</span> <span class="token string">""</span><span class="token punctuation">)</span>
	pdf<span class="token punctuation">.</span><span class="token function">AddPage</span><span class="token punctuation">(</span><span class="token punctuation">)</span>
	<span class="token keyword">var</span> draw <span class="token operator">=</span> <span class="token keyword">func</span><span class="token punctuation">(</span><span class="token builtin">cap</span><span class="token punctuation">,</span> join <span class="token builtin">string</span><span class="token punctuation">,</span> x0<span class="token punctuation">,</span> y0<span class="token punctuation">,</span> x1<span class="token punctuation">,</span> y1 <span class="token builtin">float64</span><span class="token punctuation">)</span> <span class="token punctuation">&#123;</span>
		<span class="token comment">// transform begin &amp; end needed to isolate caps and joins</span>
		pdf<span class="token punctuation">.</span><span class="token function">SetLineCapStyle</span><span class="token punctuation">(</span><span class="token builtin">cap</span><span class="token punctuation">)</span>
		pdf<span class="token punctuation">.</span><span class="token function">SetLineJoinStyle</span><span class="token punctuation">(</span>join<span class="token punctuation">)</span>

		<span class="token comment">// Draw thick line</span>
		pdf<span class="token punctuation">.</span><span class="token function">SetDrawColor</span><span class="token punctuation">(</span><span class="token number">0x33</span><span class="token punctuation">,</span> <span class="token number">0x33</span><span class="token punctuation">,</span> <span class="token number">0x33</span><span class="token punctuation">)</span>
		pdf<span class="token punctuation">.</span><span class="token function">SetLineWidth</span><span class="token punctuation">(</span><span class="token number">30.0</span><span class="token punctuation">)</span>
		pdf<span class="token punctuation">.</span><span class="token function">MoveTo</span><span class="token punctuation">(</span>x0<span class="token punctuation">,</span> y0<span class="token punctuation">)</span>
		pdf<span class="token punctuation">.</span><span class="token function">LineTo</span><span class="token punctuation">(</span><span class="token punctuation">(</span>x0<span class="token operator">+</span>x1<span class="token punctuation">)</span><span class="token operator">/</span><span class="token number">2</span><span class="token operator">+</span>offset<span class="token punctuation">,</span> <span class="token punctuation">(</span>y0<span class="token operator">+</span>y1<span class="token punctuation">)</span><span class="token operator">/</span><span class="token number">2</span><span class="token punctuation">)</span>
		pdf<span class="token punctuation">.</span><span class="token function">LineTo</span><span class="token punctuation">(</span>x1<span class="token punctuation">,</span> y1<span class="token punctuation">)</span>
		pdf<span class="token punctuation">.</span><span class="token function">DrawPath</span><span class="token punctuation">(</span><span class="token string">"D"</span><span class="token punctuation">)</span>

		<span class="token comment">// Draw thin helping line</span>
		pdf<span class="token punctuation">.</span><span class="token function">SetDrawColor</span><span class="token punctuation">(</span><span class="token number">0xFF</span><span class="token punctuation">,</span> <span class="token number">0x33</span><span class="token punctuation">,</span> <span class="token number">0x33</span><span class="token punctuation">)</span>
		pdf<span class="token punctuation">.</span><span class="token function">SetLineWidth</span><span class="token punctuation">(</span><span class="token number">2.56</span><span class="token punctuation">)</span>
		pdf<span class="token punctuation">.</span><span class="token function">MoveTo</span><span class="token punctuation">(</span>x0<span class="token punctuation">,</span> y0<span class="token punctuation">)</span>
		pdf<span class="token punctuation">.</span><span class="token function">LineTo</span><span class="token punctuation">(</span><span class="token punctuation">(</span>x0<span class="token operator">+</span>x1<span class="token punctuation">)</span><span class="token operator">/</span><span class="token number">2</span><span class="token operator">+</span>offset<span class="token punctuation">,</span> <span class="token punctuation">(</span>y0<span class="token operator">+</span>y1<span class="token punctuation">)</span><span class="token operator">/</span><span class="token number">2</span><span class="token punctuation">)</span>
		pdf<span class="token punctuation">.</span><span class="token function">LineTo</span><span class="token punctuation">(</span>x1<span class="token punctuation">,</span> y1<span class="token punctuation">)</span>
		pdf<span class="token punctuation">.</span><span class="token function">DrawPath</span><span class="token punctuation">(</span><span class="token string">"D"</span><span class="token punctuation">)</span>

	<span class="token punctuation">&#125;</span>
	x <span class="token operator">:=</span> <span class="token number">35.0</span>
	caps <span class="token operator">:=</span> <span class="token punctuation">[</span><span class="token punctuation">]</span><span class="token builtin">string</span><span class="token punctuation">&#123;</span><span class="token string">"butt"</span><span class="token punctuation">,</span> <span class="token string">"square"</span><span class="token punctuation">,</span> <span class="token string">"round"</span><span class="token punctuation">&#125;</span>
	joins <span class="token operator">:=</span> <span class="token punctuation">[</span><span class="token punctuation">]</span><span class="token builtin">string</span><span class="token punctuation">&#123;</span><span class="token string">"bevel"</span><span class="token punctuation">,</span> <span class="token string">"miter"</span><span class="token punctuation">,</span> <span class="token string">"round"</span><span class="token punctuation">&#125;</span>
	<span class="token keyword">for</span> i <span class="token operator">:=</span> <span class="token keyword">range</span> caps <span class="token punctuation">&#123;</span>
		<span class="token function">draw</span><span class="token punctuation">(</span>caps<span class="token punctuation">[</span>i<span class="token punctuation">]</span><span class="token punctuation">,</span> joins<span class="token punctuation">[</span>i<span class="token punctuation">]</span><span class="token punctuation">,</span> x<span class="token punctuation">,</span> <span class="token number">50</span><span class="token punctuation">,</span> x<span class="token punctuation">,</span> <span class="token number">160</span><span class="token punctuation">)</span>
		x <span class="token operator">+=</span> offset
	<span class="token punctuation">&#125;</span>
	fileStr <span class="token operator">:=</span> example<span class="token punctuation">.</span><span class="token function">Filename</span><span class="token punctuation">(</span><span class="token string">"Fpdf_SetLineJoinStyle_caps"</span><span class="token punctuation">)</span>
	err <span class="token operator">:=</span> pdf<span class="token punctuation">.</span><span class="token function">OutputFileAndClose</span><span class="token punctuation">(</span>fileStr<span class="token punctuation">)</span>
	example<span class="token punctuation">.</span><span class="token function">Summary</span><span class="token punctuation">(</span>err<span class="token punctuation">,</span> fileStr<span class="token punctuation">)</span>
	<span class="token comment">// Output:</span>
	<span class="token comment">// Successfully generated pdf/Fpdf_SetLineJoinStyle_caps.pdf</span>
<span class="token punctuation">&#125;</span></code></pre>

<h2 id="演示各种填充模式"><a href="#演示各种填充模式" class="headerlink" title="演示各种填充模式"></a>演示各种填充模式</h2><pre class="language-go" data-language="go"><code class="language-go"><span class="token comment">// ExampleFpdf_DrawPath demonstrates various fill modes.</span>
<span class="token keyword">func</span> <span class="token function">ExampleFpdf_DrawPath</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">&#123;</span>
	pdf <span class="token operator">:=</span> gofpdf<span class="token punctuation">.</span><span class="token function">New</span><span class="token punctuation">(</span><span class="token string">"P"</span><span class="token punctuation">,</span> <span class="token string">"mm"</span><span class="token punctuation">,</span> <span class="token string">"A4"</span><span class="token punctuation">,</span> <span class="token string">""</span><span class="token punctuation">)</span>
	pdf<span class="token punctuation">.</span><span class="token function">SetDrawColor</span><span class="token punctuation">(</span><span class="token number">0xff</span><span class="token punctuation">,</span> <span class="token number">0x00</span><span class="token punctuation">,</span> <span class="token number">0x00</span><span class="token punctuation">)</span>
	pdf<span class="token punctuation">.</span><span class="token function">SetFillColor</span><span class="token punctuation">(</span><span class="token number">0x99</span><span class="token punctuation">,</span> <span class="token number">0x99</span><span class="token punctuation">,</span> <span class="token number">0x99</span><span class="token punctuation">)</span>
	pdf<span class="token punctuation">.</span><span class="token function">SetFont</span><span class="token punctuation">(</span><span class="token string">"Helvetica"</span><span class="token punctuation">,</span> <span class="token string">""</span><span class="token punctuation">,</span> <span class="token number">15</span><span class="token punctuation">)</span>
	pdf<span class="token punctuation">.</span><span class="token function">AddPage</span><span class="token punctuation">(</span><span class="token punctuation">)</span>
	pdf<span class="token punctuation">.</span><span class="token function">SetAlpha</span><span class="token punctuation">(</span><span class="token number">1</span><span class="token punctuation">,</span> <span class="token string">"Multiply"</span><span class="token punctuation">)</span>
	<span class="token keyword">var</span> <span class="token punctuation">(</span>
		polygon <span class="token operator">=</span> <span class="token keyword">func</span><span class="token punctuation">(</span>cx<span class="token punctuation">,</span> cy<span class="token punctuation">,</span> r<span class="token punctuation">,</span> n<span class="token punctuation">,</span> dir <span class="token builtin">float64</span><span class="token punctuation">)</span> <span class="token punctuation">&#123;</span>
			da <span class="token operator">:=</span> <span class="token number">2</span> <span class="token operator">*</span> math<span class="token punctuation">.</span>Pi <span class="token operator">/</span> n
			pdf<span class="token punctuation">.</span><span class="token function">MoveTo</span><span class="token punctuation">(</span>cx<span class="token operator">+</span>r<span class="token punctuation">,</span> cy<span class="token punctuation">)</span>
			pdf<span class="token punctuation">.</span><span class="token function">Text</span><span class="token punctuation">(</span>cx<span class="token operator">+</span>r<span class="token punctuation">,</span> cy<span class="token punctuation">,</span> <span class="token string">"0"</span><span class="token punctuation">)</span>
			i <span class="token operator">:=</span> <span class="token number">1</span>
			<span class="token keyword">for</span> a <span class="token operator">:=</span> da<span class="token punctuation">;</span> a <span class="token operator">&lt;</span> <span class="token number">2</span><span class="token operator">*</span>math<span class="token punctuation">.</span>Pi<span class="token punctuation">;</span> a <span class="token operator">+=</span> da <span class="token punctuation">&#123;</span>
				x<span class="token punctuation">,</span> y <span class="token operator">:=</span> cx<span class="token operator">+</span>r<span class="token operator">*</span>math<span class="token punctuation">.</span><span class="token function">Cos</span><span class="token punctuation">(</span>dir<span class="token operator">*</span>a<span class="token punctuation">)</span><span class="token punctuation">,</span> cy<span class="token operator">+</span>r<span class="token operator">*</span>math<span class="token punctuation">.</span><span class="token function">Sin</span><span class="token punctuation">(</span>dir<span class="token operator">*</span>a<span class="token punctuation">)</span>
				pdf<span class="token punctuation">.</span><span class="token function">LineTo</span><span class="token punctuation">(</span>x<span class="token punctuation">,</span> y<span class="token punctuation">)</span>
				pdf<span class="token punctuation">.</span><span class="token function">Text</span><span class="token punctuation">(</span>x<span class="token punctuation">,</span> y<span class="token punctuation">,</span> strconv<span class="token punctuation">.</span><span class="token function">Itoa</span><span class="token punctuation">(</span>i<span class="token punctuation">)</span><span class="token punctuation">)</span>
				i<span class="token operator">++</span>
			<span class="token punctuation">&#125;</span>
			pdf<span class="token punctuation">.</span><span class="token function">ClosePath</span><span class="token punctuation">(</span><span class="token punctuation">)</span>
		<span class="token punctuation">&#125;</span>
		polygons <span class="token operator">=</span> <span class="token keyword">func</span><span class="token punctuation">(</span>cx<span class="token punctuation">,</span> cy<span class="token punctuation">,</span> r<span class="token punctuation">,</span> n<span class="token punctuation">,</span> dir <span class="token builtin">float64</span><span class="token punctuation">)</span> <span class="token punctuation">&#123;</span>
			d <span class="token operator">:=</span> <span class="token number">1.0</span>
			<span class="token keyword">for</span> rf <span class="token operator">:=</span> r<span class="token punctuation">;</span> rf <span class="token operator">></span> <span class="token number">0</span><span class="token punctuation">;</span> rf <span class="token operator">-=</span> <span class="token number">10</span> <span class="token punctuation">&#123;</span>
				<span class="token function">polygon</span><span class="token punctuation">(</span>cx<span class="token punctuation">,</span> cy<span class="token punctuation">,</span> rf<span class="token punctuation">,</span> n<span class="token punctuation">,</span> d<span class="token punctuation">)</span>
				d <span class="token operator">*=</span> dir
			<span class="token punctuation">&#125;</span>
		<span class="token punctuation">&#125;</span>
		star <span class="token operator">=</span> <span class="token keyword">func</span><span class="token punctuation">(</span>cx<span class="token punctuation">,</span> cy<span class="token punctuation">,</span> r<span class="token punctuation">,</span> n <span class="token builtin">float64</span><span class="token punctuation">)</span> <span class="token punctuation">&#123;</span>
			da <span class="token operator">:=</span> <span class="token number">4</span> <span class="token operator">*</span> math<span class="token punctuation">.</span>Pi <span class="token operator">/</span> n
			pdf<span class="token punctuation">.</span><span class="token function">MoveTo</span><span class="token punctuation">(</span>cx<span class="token operator">+</span>r<span class="token punctuation">,</span> cy<span class="token punctuation">)</span>
			<span class="token keyword">for</span> a <span class="token operator">:=</span> da<span class="token punctuation">;</span> a <span class="token operator">&lt;</span> <span class="token number">4</span><span class="token operator">*</span>math<span class="token punctuation">.</span>Pi<span class="token operator">+</span>da<span class="token punctuation">;</span> a <span class="token operator">+=</span> da <span class="token punctuation">&#123;</span>
				x<span class="token punctuation">,</span> y <span class="token operator">:=</span> cx<span class="token operator">+</span>r<span class="token operator">*</span>math<span class="token punctuation">.</span><span class="token function">Cos</span><span class="token punctuation">(</span>a<span class="token punctuation">)</span><span class="token punctuation">,</span> cy<span class="token operator">+</span>r<span class="token operator">*</span>math<span class="token punctuation">.</span><span class="token function">Sin</span><span class="token punctuation">(</span>a<span class="token punctuation">)</span>
				pdf<span class="token punctuation">.</span><span class="token function">LineTo</span><span class="token punctuation">(</span>x<span class="token punctuation">,</span> y<span class="token punctuation">)</span>
			<span class="token punctuation">&#125;</span>
			pdf<span class="token punctuation">.</span><span class="token function">ClosePath</span><span class="token punctuation">(</span><span class="token punctuation">)</span>
		<span class="token punctuation">&#125;</span>
	<span class="token punctuation">)</span>
	<span class="token comment">// triangle</span>
	<span class="token function">polygons</span><span class="token punctuation">(</span><span class="token number">55</span><span class="token punctuation">,</span> <span class="token number">45</span><span class="token punctuation">,</span> <span class="token number">40</span><span class="token punctuation">,</span> <span class="token number">3</span><span class="token punctuation">,</span> <span class="token number">1</span><span class="token punctuation">)</span>
	pdf<span class="token punctuation">.</span><span class="token function">DrawPath</span><span class="token punctuation">(</span><span class="token string">"B"</span><span class="token punctuation">)</span>
	pdf<span class="token punctuation">.</span><span class="token function">Text</span><span class="token punctuation">(</span><span class="token number">15</span><span class="token punctuation">,</span> <span class="token number">95</span><span class="token punctuation">,</span> <span class="token string">"B (same direction, non zero winding)"</span><span class="token punctuation">)</span>

	<span class="token comment">// square</span>
	<span class="token function">polygons</span><span class="token punctuation">(</span><span class="token number">155</span><span class="token punctuation">,</span> <span class="token number">45</span><span class="token punctuation">,</span> <span class="token number">40</span><span class="token punctuation">,</span> <span class="token number">4</span><span class="token punctuation">,</span> <span class="token number">1</span><span class="token punctuation">)</span>
	pdf<span class="token punctuation">.</span><span class="token function">DrawPath</span><span class="token punctuation">(</span><span class="token string">"B*"</span><span class="token punctuation">)</span>
	pdf<span class="token punctuation">.</span><span class="token function">Text</span><span class="token punctuation">(</span><span class="token number">115</span><span class="token punctuation">,</span> <span class="token number">95</span><span class="token punctuation">,</span> <span class="token string">"B* (same direction, even odd)"</span><span class="token punctuation">)</span>

	<span class="token comment">// pentagon</span>
	<span class="token function">polygons</span><span class="token punctuation">(</span><span class="token number">55</span><span class="token punctuation">,</span> <span class="token number">145</span><span class="token punctuation">,</span> <span class="token number">40</span><span class="token punctuation">,</span> <span class="token number">5</span><span class="token punctuation">,</span> <span class="token operator">-</span><span class="token number">1</span><span class="token punctuation">)</span>
	pdf<span class="token punctuation">.</span><span class="token function">DrawPath</span><span class="token punctuation">(</span><span class="token string">"B"</span><span class="token punctuation">)</span>
	pdf<span class="token punctuation">.</span><span class="token function">Text</span><span class="token punctuation">(</span><span class="token number">15</span><span class="token punctuation">,</span> <span class="token number">195</span><span class="token punctuation">,</span> <span class="token string">"B (different direction, non zero winding)"</span><span class="token punctuation">)</span>

	<span class="token comment">// hexagon</span>
	<span class="token function">polygons</span><span class="token punctuation">(</span><span class="token number">155</span><span class="token punctuation">,</span> <span class="token number">145</span><span class="token punctuation">,</span> <span class="token number">40</span><span class="token punctuation">,</span> <span class="token number">6</span><span class="token punctuation">,</span> <span class="token operator">-</span><span class="token number">1</span><span class="token punctuation">)</span>
	pdf<span class="token punctuation">.</span><span class="token function">DrawPath</span><span class="token punctuation">(</span><span class="token string">"B*"</span><span class="token punctuation">)</span>
	pdf<span class="token punctuation">.</span><span class="token function">Text</span><span class="token punctuation">(</span><span class="token number">115</span><span class="token punctuation">,</span> <span class="token number">195</span><span class="token punctuation">,</span> <span class="token string">"B* (different direction, even odd)"</span><span class="token punctuation">)</span>

	<span class="token comment">// star</span>
	<span class="token function">star</span><span class="token punctuation">(</span><span class="token number">55</span><span class="token punctuation">,</span> <span class="token number">245</span><span class="token punctuation">,</span> <span class="token number">40</span><span class="token punctuation">,</span> <span class="token number">5</span><span class="token punctuation">)</span>
	pdf<span class="token punctuation">.</span><span class="token function">DrawPath</span><span class="token punctuation">(</span><span class="token string">"B"</span><span class="token punctuation">)</span>
	pdf<span class="token punctuation">.</span><span class="token function">Text</span><span class="token punctuation">(</span><span class="token number">15</span><span class="token punctuation">,</span> <span class="token number">290</span><span class="token punctuation">,</span> <span class="token string">"B (non zero winding)"</span><span class="token punctuation">)</span>

	<span class="token comment">// star</span>
	<span class="token function">star</span><span class="token punctuation">(</span><span class="token number">155</span><span class="token punctuation">,</span> <span class="token number">245</span><span class="token punctuation">,</span> <span class="token number">40</span><span class="token punctuation">,</span> <span class="token number">5</span><span class="token punctuation">)</span>
	pdf<span class="token punctuation">.</span><span class="token function">DrawPath</span><span class="token punctuation">(</span><span class="token string">"B*"</span><span class="token punctuation">)</span>
	pdf<span class="token punctuation">.</span><span class="token function">Text</span><span class="token punctuation">(</span><span class="token number">115</span><span class="token punctuation">,</span> <span class="token number">290</span><span class="token punctuation">,</span> <span class="token string">"B* (even odd)"</span><span class="token punctuation">)</span>

	fileStr <span class="token operator">:=</span> example<span class="token punctuation">.</span><span class="token function">Filename</span><span class="token punctuation">(</span><span class="token string">"Fpdf_DrawPath_fill"</span><span class="token punctuation">)</span>
	err <span class="token operator">:=</span> pdf<span class="token punctuation">.</span><span class="token function">OutputFileAndClose</span><span class="token punctuation">(</span>fileStr<span class="token punctuation">)</span>
	example<span class="token punctuation">.</span><span class="token function">Summary</span><span class="token punctuation">(</span>err<span class="token punctuation">,</span> fileStr<span class="token punctuation">)</span>
	<span class="token comment">// Output:</span>
	<span class="token comment">// Successfully generated pdf/Fpdf_DrawPath_fill.pdf</span>
<span class="token punctuation">&#125;</span></code></pre>

<h2 id="演示创建和使用模板"><a href="#演示创建和使用模板" class="headerlink" title="演示创建和使用模板"></a>演示创建和使用模板</h2><pre class="language-go" data-language="go"><code class="language-go"><span class="token comment">// ExampleFpdf_CreateTemplate demonstrates creating and using templates</span>
<span class="token keyword">func</span> <span class="token function">ExampleFpdf_CreateTemplate</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">&#123;</span>
	pdf <span class="token operator">:=</span> gofpdf<span class="token punctuation">.</span><span class="token function">New</span><span class="token punctuation">(</span><span class="token string">"P"</span><span class="token punctuation">,</span> <span class="token string">"mm"</span><span class="token punctuation">,</span> <span class="token string">"A4"</span><span class="token punctuation">,</span> <span class="token string">""</span><span class="token punctuation">)</span>
	pdf<span class="token punctuation">.</span><span class="token function">SetCompression</span><span class="token punctuation">(</span><span class="token boolean">false</span><span class="token punctuation">)</span>
	<span class="token comment">// pdf.SetFont("Times", "", 12)</span>
	template <span class="token operator">:=</span> pdf<span class="token punctuation">.</span><span class="token function">CreateTemplate</span><span class="token punctuation">(</span><span class="token keyword">func</span><span class="token punctuation">(</span>tpl <span class="token operator">*</span>gofpdf<span class="token punctuation">.</span>Tpl<span class="token punctuation">)</span> <span class="token punctuation">&#123;</span>
		tpl<span class="token punctuation">.</span><span class="token function">Image</span><span class="token punctuation">(</span>example<span class="token punctuation">.</span><span class="token function">ImageFile</span><span class="token punctuation">(</span><span class="token string">"logo.png"</span><span class="token punctuation">)</span><span class="token punctuation">,</span> <span class="token number">6</span><span class="token punctuation">,</span> <span class="token number">6</span><span class="token punctuation">,</span> <span class="token number">30</span><span class="token punctuation">,</span> <span class="token number">0</span><span class="token punctuation">,</span> <span class="token boolean">false</span><span class="token punctuation">,</span> <span class="token string">""</span><span class="token punctuation">,</span> <span class="token number">0</span><span class="token punctuation">,</span> <span class="token string">""</span><span class="token punctuation">)</span>
		tpl<span class="token punctuation">.</span><span class="token function">SetFont</span><span class="token punctuation">(</span><span class="token string">"Arial"</span><span class="token punctuation">,</span> <span class="token string">"B"</span><span class="token punctuation">,</span> <span class="token number">16</span><span class="token punctuation">)</span>
		tpl<span class="token punctuation">.</span><span class="token function">Text</span><span class="token punctuation">(</span><span class="token number">40</span><span class="token punctuation">,</span> <span class="token number">20</span><span class="token punctuation">,</span> <span class="token string">"Template says hello"</span><span class="token punctuation">)</span>
		tpl<span class="token punctuation">.</span><span class="token function">SetDrawColor</span><span class="token punctuation">(</span><span class="token number">0</span><span class="token punctuation">,</span> <span class="token number">100</span><span class="token punctuation">,</span> <span class="token number">200</span><span class="token punctuation">)</span>
		tpl<span class="token punctuation">.</span><span class="token function">SetLineWidth</span><span class="token punctuation">(</span><span class="token number">2.5</span><span class="token punctuation">)</span>
		tpl<span class="token punctuation">.</span><span class="token function">Line</span><span class="token punctuation">(</span><span class="token number">95</span><span class="token punctuation">,</span> <span class="token number">12</span><span class="token punctuation">,</span> <span class="token number">105</span><span class="token punctuation">,</span> <span class="token number">22</span><span class="token punctuation">)</span>
	<span class="token punctuation">&#125;</span><span class="token punctuation">)</span>
	<span class="token boolean">_</span><span class="token punctuation">,</span> tplSize <span class="token operator">:=</span> template<span class="token punctuation">.</span><span class="token function">Size</span><span class="token punctuation">(</span><span class="token punctuation">)</span>
	<span class="token comment">// fmt.Println("Size:", tplSize)</span>
	<span class="token comment">// fmt.Println("Scaled:", tplSize.ScaleBy(1.5))</span>

	template2 <span class="token operator">:=</span> pdf<span class="token punctuation">.</span><span class="token function">CreateTemplate</span><span class="token punctuation">(</span><span class="token keyword">func</span><span class="token punctuation">(</span>tpl <span class="token operator">*</span>gofpdf<span class="token punctuation">.</span>Tpl<span class="token punctuation">)</span> <span class="token punctuation">&#123;</span>
		tpl<span class="token punctuation">.</span><span class="token function">UseTemplate</span><span class="token punctuation">(</span>template<span class="token punctuation">)</span>
		subtemplate <span class="token operator">:=</span> tpl<span class="token punctuation">.</span><span class="token function">CreateTemplate</span><span class="token punctuation">(</span><span class="token keyword">func</span><span class="token punctuation">(</span>tpl2 <span class="token operator">*</span>gofpdf<span class="token punctuation">.</span>Tpl<span class="token punctuation">)</span> <span class="token punctuation">&#123;</span>
			tpl2<span class="token punctuation">.</span><span class="token function">Image</span><span class="token punctuation">(</span>example<span class="token punctuation">.</span><span class="token function">ImageFile</span><span class="token punctuation">(</span><span class="token string">"logo.png"</span><span class="token punctuation">)</span><span class="token punctuation">,</span> <span class="token number">6</span><span class="token punctuation">,</span> <span class="token number">86</span><span class="token punctuation">,</span> <span class="token number">30</span><span class="token punctuation">,</span> <span class="token number">0</span><span class="token punctuation">,</span> <span class="token boolean">false</span><span class="token punctuation">,</span> <span class="token string">""</span><span class="token punctuation">,</span> <span class="token number">0</span><span class="token punctuation">,</span> <span class="token string">""</span><span class="token punctuation">)</span>
			tpl2<span class="token punctuation">.</span><span class="token function">SetFont</span><span class="token punctuation">(</span><span class="token string">"Arial"</span><span class="token punctuation">,</span> <span class="token string">"B"</span><span class="token punctuation">,</span> <span class="token number">16</span><span class="token punctuation">)</span>
			tpl2<span class="token punctuation">.</span><span class="token function">Text</span><span class="token punctuation">(</span><span class="token number">40</span><span class="token punctuation">,</span> <span class="token number">100</span><span class="token punctuation">,</span> <span class="token string">"Subtemplate says hello"</span><span class="token punctuation">)</span>
			tpl2<span class="token punctuation">.</span><span class="token function">SetDrawColor</span><span class="token punctuation">(</span><span class="token number">0</span><span class="token punctuation">,</span> <span class="token number">200</span><span class="token punctuation">,</span> <span class="token number">100</span><span class="token punctuation">)</span>
			tpl2<span class="token punctuation">.</span><span class="token function">SetLineWidth</span><span class="token punctuation">(</span><span class="token number">2.5</span><span class="token punctuation">)</span>
			tpl2<span class="token punctuation">.</span><span class="token function">Line</span><span class="token punctuation">(</span><span class="token number">102</span><span class="token punctuation">,</span> <span class="token number">92</span><span class="token punctuation">,</span> <span class="token number">112</span><span class="token punctuation">,</span> <span class="token number">102</span><span class="token punctuation">)</span>
		<span class="token punctuation">&#125;</span><span class="token punctuation">)</span>
		tpl<span class="token punctuation">.</span><span class="token function">UseTemplate</span><span class="token punctuation">(</span>subtemplate<span class="token punctuation">)</span>
	<span class="token punctuation">&#125;</span><span class="token punctuation">)</span>

	pdf<span class="token punctuation">.</span><span class="token function">SetDrawColor</span><span class="token punctuation">(</span><span class="token number">200</span><span class="token punctuation">,</span> <span class="token number">100</span><span class="token punctuation">,</span> <span class="token number">0</span><span class="token punctuation">)</span>
	pdf<span class="token punctuation">.</span><span class="token function">SetLineWidth</span><span class="token punctuation">(</span><span class="token number">2.5</span><span class="token punctuation">)</span>
	pdf<span class="token punctuation">.</span><span class="token function">SetFont</span><span class="token punctuation">(</span><span class="token string">"Arial"</span><span class="token punctuation">,</span> <span class="token string">"B"</span><span class="token punctuation">,</span> <span class="token number">16</span><span class="token punctuation">)</span>

	<span class="token comment">// serialize and deserialize template</span>
	b<span class="token punctuation">,</span> <span class="token boolean">_</span> <span class="token operator">:=</span> template2<span class="token punctuation">.</span><span class="token function">Serialize</span><span class="token punctuation">(</span><span class="token punctuation">)</span>
	template3<span class="token punctuation">,</span> <span class="token boolean">_</span> <span class="token operator">:=</span> gofpdf<span class="token punctuation">.</span><span class="token function">DeserializeTemplate</span><span class="token punctuation">(</span>b<span class="token punctuation">)</span>

	pdf<span class="token punctuation">.</span><span class="token function">AddPage</span><span class="token punctuation">(</span><span class="token punctuation">)</span>
	pdf<span class="token punctuation">.</span><span class="token function">UseTemplate</span><span class="token punctuation">(</span>template3<span class="token punctuation">)</span>
	pdf<span class="token punctuation">.</span><span class="token function">UseTemplateScaled</span><span class="token punctuation">(</span>template3<span class="token punctuation">,</span> gofpdf<span class="token punctuation">.</span>PointType<span class="token punctuation">&#123;</span>X<span class="token punctuation">:</span> <span class="token number">0</span><span class="token punctuation">,</span> Y<span class="token punctuation">:</span> <span class="token number">30</span><span class="token punctuation">&#125;</span><span class="token punctuation">,</span> tplSize<span class="token punctuation">)</span>
	pdf<span class="token punctuation">.</span><span class="token function">Line</span><span class="token punctuation">(</span><span class="token number">40</span><span class="token punctuation">,</span> <span class="token number">210</span><span class="token punctuation">,</span> <span class="token number">60</span><span class="token punctuation">,</span> <span class="token number">210</span><span class="token punctuation">)</span>
	pdf<span class="token punctuation">.</span><span class="token function">Text</span><span class="token punctuation">(</span><span class="token number">40</span><span class="token punctuation">,</span> <span class="token number">200</span><span class="token punctuation">,</span> <span class="token string">"Template example page 1"</span><span class="token punctuation">)</span>

	pdf<span class="token punctuation">.</span><span class="token function">AddPage</span><span class="token punctuation">(</span><span class="token punctuation">)</span>
	pdf<span class="token punctuation">.</span><span class="token function">UseTemplate</span><span class="token punctuation">(</span>template2<span class="token punctuation">)</span>
	pdf<span class="token punctuation">.</span><span class="token function">UseTemplateScaled</span><span class="token punctuation">(</span>template3<span class="token punctuation">,</span> gofpdf<span class="token punctuation">.</span>PointType<span class="token punctuation">&#123;</span>X<span class="token punctuation">:</span> <span class="token number">0</span><span class="token punctuation">,</span> Y<span class="token punctuation">:</span> <span class="token number">30</span><span class="token punctuation">&#125;</span><span class="token punctuation">,</span> tplSize<span class="token punctuation">.</span><span class="token function">ScaleBy</span><span class="token punctuation">(</span><span class="token number">1.4</span><span class="token punctuation">)</span><span class="token punctuation">)</span>
	pdf<span class="token punctuation">.</span><span class="token function">Line</span><span class="token punctuation">(</span><span class="token number">60</span><span class="token punctuation">,</span> <span class="token number">210</span><span class="token punctuation">,</span> <span class="token number">80</span><span class="token punctuation">,</span> <span class="token number">210</span><span class="token punctuation">)</span>
	pdf<span class="token punctuation">.</span><span class="token function">Text</span><span class="token punctuation">(</span><span class="token number">40</span><span class="token punctuation">,</span> <span class="token number">200</span><span class="token punctuation">,</span> <span class="token string">"Template example page 2"</span><span class="token punctuation">)</span>

	fileStr <span class="token operator">:=</span> example<span class="token punctuation">.</span><span class="token function">Filename</span><span class="token punctuation">(</span><span class="token string">"Fpdf_CreateTemplate"</span><span class="token punctuation">)</span>
	err <span class="token operator">:=</span> pdf<span class="token punctuation">.</span><span class="token function">OutputFileAndClose</span><span class="token punctuation">(</span>fileStr<span class="token punctuation">)</span>
	example<span class="token punctuation">.</span><span class="token function">Summary</span><span class="token punctuation">(</span>err<span class="token punctuation">,</span> fileStr<span class="token punctuation">)</span>
	<span class="token comment">// Output:</span>
	<span class="token comment">// Successfully generated pdf/Fpdf_CreateTemplate.pdf</span>
<span class="token punctuation">&#125;</span></code></pre>

<h2 id="演示如何使用字节数组中的嵌入字体"><a href="#演示如何使用字节数组中的嵌入字体" class="headerlink" title="演示如何使用字节数组中的嵌入字体"></a>演示如何使用字节数组中的嵌入字体</h2><pre class="language-go" data-language="go"><code class="language-go"><span class="token comment">// ExampleFpdf_AddFontFromBytes demonstrate how to use embedded fonts from byte array</span>
<span class="token keyword">func</span> <span class="token function">ExampleFpdf_AddFontFromBytes</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">&#123;</span>
	pdf <span class="token operator">:=</span> gofpdf<span class="token punctuation">.</span><span class="token function">New</span><span class="token punctuation">(</span><span class="token string">"P"</span><span class="token punctuation">,</span> <span class="token string">"mm"</span><span class="token punctuation">,</span> <span class="token string">"A4"</span><span class="token punctuation">,</span> <span class="token string">""</span><span class="token punctuation">)</span>
	pdf<span class="token punctuation">.</span><span class="token function">AddPage</span><span class="token punctuation">(</span><span class="token punctuation">)</span>
	pdf<span class="token punctuation">.</span><span class="token function">AddFontFromBytes</span><span class="token punctuation">(</span><span class="token string">"calligra"</span><span class="token punctuation">,</span> <span class="token string">""</span><span class="token punctuation">,</span> files<span class="token punctuation">.</span>CalligraJson<span class="token punctuation">,</span> files<span class="token punctuation">.</span>CalligraZ<span class="token punctuation">)</span>
	pdf<span class="token punctuation">.</span><span class="token function">SetFont</span><span class="token punctuation">(</span><span class="token string">"calligra"</span><span class="token punctuation">,</span> <span class="token string">""</span><span class="token punctuation">,</span> <span class="token number">16</span><span class="token punctuation">)</span>
	pdf<span class="token punctuation">.</span><span class="token function">Cell</span><span class="token punctuation">(</span><span class="token number">40</span><span class="token punctuation">,</span> <span class="token number">10</span><span class="token punctuation">,</span> <span class="token string">"Hello World With Embedded Font!"</span><span class="token punctuation">)</span>
	fileStr <span class="token operator">:=</span> example<span class="token punctuation">.</span><span class="token function">Filename</span><span class="token punctuation">(</span><span class="token string">"Fpdf_EmbeddedFont"</span><span class="token punctuation">)</span>
	err <span class="token operator">:=</span> pdf<span class="token punctuation">.</span><span class="token function">OutputFileAndClose</span><span class="token punctuation">(</span>fileStr<span class="token punctuation">)</span>
	example<span class="token punctuation">.</span><span class="token function">Summary</span><span class="token punctuation">(</span>err<span class="token punctuation">,</span> fileStr<span class="token punctuation">)</span>
	<span class="token comment">// Output:</span>
	<span class="token comment">// Successfully generated pdf/Fpdf_EmbeddedFont.pdf</span>
<span class="token punctuation">&#125;</span></code></pre>

<h2 id="演示了剪切的表格单元格"><a href="#演示了剪切的表格单元格" class="headerlink" title="演示了剪切的表格单元格"></a>演示了剪切的表格单元格</h2><pre class="language-go" data-language="go"><code class="language-go"><span class="token comment">// This example demonstrate Clipped table cells</span>
<span class="token keyword">func</span> <span class="token function">ExampleFpdf_ClipRect</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">&#123;</span>
	marginCell <span class="token operator">:=</span> <span class="token number">2.</span> <span class="token comment">// margin of top/bottom of cell</span>
	pdf <span class="token operator">:=</span> gofpdf<span class="token punctuation">.</span><span class="token function">New</span><span class="token punctuation">(</span><span class="token string">"P"</span><span class="token punctuation">,</span> <span class="token string">"mm"</span><span class="token punctuation">,</span> <span class="token string">"A4"</span><span class="token punctuation">,</span> <span class="token string">""</span><span class="token punctuation">)</span>
	pdf<span class="token punctuation">.</span><span class="token function">SetFont</span><span class="token punctuation">(</span><span class="token string">"Arial"</span><span class="token punctuation">,</span> <span class="token string">""</span><span class="token punctuation">,</span> <span class="token number">12</span><span class="token punctuation">)</span>
	pdf<span class="token punctuation">.</span><span class="token function">AddPage</span><span class="token punctuation">(</span><span class="token punctuation">)</span>
	pagew<span class="token punctuation">,</span> pageh <span class="token operator">:=</span> pdf<span class="token punctuation">.</span><span class="token function">GetPageSize</span><span class="token punctuation">(</span><span class="token punctuation">)</span>
	mleft<span class="token punctuation">,</span> mright<span class="token punctuation">,</span> <span class="token boolean">_</span><span class="token punctuation">,</span> mbottom <span class="token operator">:=</span> pdf<span class="token punctuation">.</span><span class="token function">GetMargins</span><span class="token punctuation">(</span><span class="token punctuation">)</span>

	cols <span class="token operator">:=</span> <span class="token punctuation">[</span><span class="token punctuation">]</span><span class="token builtin">float64</span><span class="token punctuation">&#123;</span><span class="token number">60</span><span class="token punctuation">,</span> <span class="token number">100</span><span class="token punctuation">,</span> pagew <span class="token operator">-</span> mleft <span class="token operator">-</span> mright <span class="token operator">-</span> <span class="token number">100</span> <span class="token operator">-</span> <span class="token number">60</span><span class="token punctuation">&#125;</span>
	rows <span class="token operator">:=</span> <span class="token punctuation">[</span><span class="token punctuation">]</span><span class="token punctuation">[</span><span class="token punctuation">]</span><span class="token builtin">string</span><span class="token punctuation">&#123;</span><span class="token punctuation">&#125;</span>
	<span class="token keyword">for</span> i <span class="token operator">:=</span> <span class="token number">1</span><span class="token punctuation">;</span> i <span class="token operator">&lt;=</span> <span class="token number">50</span><span class="token punctuation">;</span> i<span class="token operator">++</span> <span class="token punctuation">&#123;</span>
		word <span class="token operator">:=</span> fmt<span class="token punctuation">.</span><span class="token function">Sprintf</span><span class="token punctuation">(</span><span class="token string">"%d:%s"</span><span class="token punctuation">,</span> i<span class="token punctuation">,</span> strings<span class="token punctuation">.</span><span class="token function">Repeat</span><span class="token punctuation">(</span><span class="token string">"A"</span><span class="token punctuation">,</span> i<span class="token operator">%</span><span class="token number">100</span><span class="token punctuation">)</span><span class="token punctuation">)</span>
		rows <span class="token operator">=</span> <span class="token function">append</span><span class="token punctuation">(</span>rows<span class="token punctuation">,</span> <span class="token punctuation">[</span><span class="token punctuation">]</span><span class="token builtin">string</span><span class="token punctuation">&#123;</span>word<span class="token punctuation">,</span> word<span class="token punctuation">,</span> word<span class="token punctuation">&#125;</span><span class="token punctuation">)</span>
	<span class="token punctuation">&#125;</span>

	<span class="token keyword">for</span> <span class="token boolean">_</span><span class="token punctuation">,</span> row <span class="token operator">:=</span> <span class="token keyword">range</span> rows <span class="token punctuation">&#123;</span>
		<span class="token boolean">_</span><span class="token punctuation">,</span> lineHt <span class="token operator">:=</span> pdf<span class="token punctuation">.</span><span class="token function">GetFontSize</span><span class="token punctuation">(</span><span class="token punctuation">)</span>
		height <span class="token operator">:=</span> lineHt <span class="token operator">+</span> marginCell

		x<span class="token punctuation">,</span> y <span class="token operator">:=</span> pdf<span class="token punctuation">.</span><span class="token function">GetXY</span><span class="token punctuation">(</span><span class="token punctuation">)</span>
		<span class="token comment">// add a new page if the height of the row doesn't fit on the page</span>
		<span class="token keyword">if</span> y<span class="token operator">+</span>height <span class="token operator">>=</span> pageh<span class="token operator">-</span>mbottom <span class="token punctuation">&#123;</span>
			pdf<span class="token punctuation">.</span><span class="token function">AddPage</span><span class="token punctuation">(</span><span class="token punctuation">)</span>
			x<span class="token punctuation">,</span> y <span class="token operator">=</span> pdf<span class="token punctuation">.</span><span class="token function">GetXY</span><span class="token punctuation">(</span><span class="token punctuation">)</span>
		<span class="token punctuation">&#125;</span>
		<span class="token keyword">for</span> i<span class="token punctuation">,</span> txt <span class="token operator">:=</span> <span class="token keyword">range</span> row <span class="token punctuation">&#123;</span>
			width <span class="token operator">:=</span> cols<span class="token punctuation">[</span>i<span class="token punctuation">]</span>
			pdf<span class="token punctuation">.</span><span class="token function">Rect</span><span class="token punctuation">(</span>x<span class="token punctuation">,</span> y<span class="token punctuation">,</span> width<span class="token punctuation">,</span> height<span class="token punctuation">,</span> <span class="token string">""</span><span class="token punctuation">)</span>
			pdf<span class="token punctuation">.</span><span class="token function">ClipRect</span><span class="token punctuation">(</span>x<span class="token punctuation">,</span> y<span class="token punctuation">,</span> width<span class="token punctuation">,</span> height<span class="token punctuation">,</span> <span class="token boolean">false</span><span class="token punctuation">)</span>
			pdf<span class="token punctuation">.</span><span class="token function">Cell</span><span class="token punctuation">(</span>width<span class="token punctuation">,</span> height<span class="token punctuation">,</span> txt<span class="token punctuation">)</span>
			pdf<span class="token punctuation">.</span><span class="token function">ClipEnd</span><span class="token punctuation">(</span><span class="token punctuation">)</span>
			x <span class="token operator">+=</span> width
		<span class="token punctuation">&#125;</span>
		pdf<span class="token punctuation">.</span><span class="token function">Ln</span><span class="token punctuation">(</span><span class="token operator">-</span><span class="token number">1</span><span class="token punctuation">)</span>
	<span class="token punctuation">&#125;</span>
	fileStr <span class="token operator">:=</span> example<span class="token punctuation">.</span><span class="token function">Filename</span><span class="token punctuation">(</span><span class="token string">"Fpdf_ClippedTableCells"</span><span class="token punctuation">)</span>
	err <span class="token operator">:=</span> pdf<span class="token punctuation">.</span><span class="token function">OutputFileAndClose</span><span class="token punctuation">(</span>fileStr<span class="token punctuation">)</span>
	example<span class="token punctuation">.</span><span class="token function">Summary</span><span class="token punctuation">(</span>err<span class="token punctuation">,</span> fileStr<span class="token punctuation">)</span>
	<span class="token comment">// Output:</span>
	<span class="token comment">// Successfully generated pdf/Fpdf_ClippedTableCells.pdf</span>
<span class="token punctuation">&#125;</span></code></pre>

<h2 id="演示包装表格单元格"><a href="#演示包装表格单元格" class="headerlink" title="演示包装表格单元格"></a>演示包装表格单元格</h2><pre class="language-go" data-language="go"><code class="language-go"><span class="token comment">// This example demonstrate wrapped table cells</span>
<span class="token keyword">func</span> <span class="token function">ExampleFpdf_Rect</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">&#123;</span>
	marginCell <span class="token operator">:=</span> <span class="token number">2.</span> <span class="token comment">// margin of top/bottom of cell</span>
	pdf <span class="token operator">:=</span> gofpdf<span class="token punctuation">.</span><span class="token function">New</span><span class="token punctuation">(</span><span class="token string">"P"</span><span class="token punctuation">,</span> <span class="token string">"mm"</span><span class="token punctuation">,</span> <span class="token string">"A4"</span><span class="token punctuation">,</span> <span class="token string">""</span><span class="token punctuation">)</span>
	pdf<span class="token punctuation">.</span><span class="token function">SetFont</span><span class="token punctuation">(</span><span class="token string">"Arial"</span><span class="token punctuation">,</span> <span class="token string">""</span><span class="token punctuation">,</span> <span class="token number">12</span><span class="token punctuation">)</span>
	pdf<span class="token punctuation">.</span><span class="token function">AddPage</span><span class="token punctuation">(</span><span class="token punctuation">)</span>
	pagew<span class="token punctuation">,</span> pageh <span class="token operator">:=</span> pdf<span class="token punctuation">.</span><span class="token function">GetPageSize</span><span class="token punctuation">(</span><span class="token punctuation">)</span>
	mleft<span class="token punctuation">,</span> mright<span class="token punctuation">,</span> <span class="token boolean">_</span><span class="token punctuation">,</span> mbottom <span class="token operator">:=</span> pdf<span class="token punctuation">.</span><span class="token function">GetMargins</span><span class="token punctuation">(</span><span class="token punctuation">)</span>

	cols <span class="token operator">:=</span> <span class="token punctuation">[</span><span class="token punctuation">]</span><span class="token builtin">float64</span><span class="token punctuation">&#123;</span><span class="token number">60</span><span class="token punctuation">,</span> <span class="token number">100</span><span class="token punctuation">,</span> pagew <span class="token operator">-</span> mleft <span class="token operator">-</span> mright <span class="token operator">-</span> <span class="token number">100</span> <span class="token operator">-</span> <span class="token number">60</span><span class="token punctuation">&#125;</span>
	rows <span class="token operator">:=</span> <span class="token punctuation">[</span><span class="token punctuation">]</span><span class="token punctuation">[</span><span class="token punctuation">]</span><span class="token builtin">string</span><span class="token punctuation">&#123;</span><span class="token punctuation">&#125;</span>
	<span class="token keyword">for</span> i <span class="token operator">:=</span> <span class="token number">1</span><span class="token punctuation">;</span> i <span class="token operator">&lt;=</span> <span class="token number">30</span><span class="token punctuation">;</span> i<span class="token operator">++</span> <span class="token punctuation">&#123;</span>
		word <span class="token operator">:=</span> fmt<span class="token punctuation">.</span><span class="token function">Sprintf</span><span class="token punctuation">(</span><span class="token string">"%d:%s"</span><span class="token punctuation">,</span> i<span class="token punctuation">,</span> strings<span class="token punctuation">.</span><span class="token function">Repeat</span><span class="token punctuation">(</span><span class="token string">"A"</span><span class="token punctuation">,</span> i<span class="token operator">%</span><span class="token number">100</span><span class="token punctuation">)</span><span class="token punctuation">)</span>
		rows <span class="token operator">=</span> <span class="token function">append</span><span class="token punctuation">(</span>rows<span class="token punctuation">,</span> <span class="token punctuation">[</span><span class="token punctuation">]</span><span class="token builtin">string</span><span class="token punctuation">&#123;</span>word<span class="token punctuation">,</span> word<span class="token punctuation">,</span> word<span class="token punctuation">&#125;</span><span class="token punctuation">)</span>
	<span class="token punctuation">&#125;</span>

	<span class="token keyword">for</span> <span class="token boolean">_</span><span class="token punctuation">,</span> row <span class="token operator">:=</span> <span class="token keyword">range</span> rows <span class="token punctuation">&#123;</span>
		curx<span class="token punctuation">,</span> y <span class="token operator">:=</span> pdf<span class="token punctuation">.</span><span class="token function">GetXY</span><span class="token punctuation">(</span><span class="token punctuation">)</span>
		x <span class="token operator">:=</span> curx

		height <span class="token operator">:=</span> <span class="token number">0.</span>
		<span class="token boolean">_</span><span class="token punctuation">,</span> lineHt <span class="token operator">:=</span> pdf<span class="token punctuation">.</span><span class="token function">GetFontSize</span><span class="token punctuation">(</span><span class="token punctuation">)</span>

		<span class="token keyword">for</span> i<span class="token punctuation">,</span> txt <span class="token operator">:=</span> <span class="token keyword">range</span> row <span class="token punctuation">&#123;</span>
			lines <span class="token operator">:=</span> pdf<span class="token punctuation">.</span><span class="token function">SplitLines</span><span class="token punctuation">(</span><span class="token punctuation">[</span><span class="token punctuation">]</span><span class="token function">byte</span><span class="token punctuation">(</span>txt<span class="token punctuation">)</span><span class="token punctuation">,</span> cols<span class="token punctuation">[</span>i<span class="token punctuation">]</span><span class="token punctuation">)</span>
			h <span class="token operator">:=</span> <span class="token function">float64</span><span class="token punctuation">(</span><span class="token function">len</span><span class="token punctuation">(</span>lines<span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token operator">*</span>lineHt <span class="token operator">+</span> marginCell<span class="token operator">*</span><span class="token function">float64</span><span class="token punctuation">(</span><span class="token function">len</span><span class="token punctuation">(</span>lines<span class="token punctuation">)</span><span class="token punctuation">)</span>
			<span class="token keyword">if</span> h <span class="token operator">></span> height <span class="token punctuation">&#123;</span>
				height <span class="token operator">=</span> h
			<span class="token punctuation">&#125;</span>
		<span class="token punctuation">&#125;</span>
		<span class="token comment">// add a new page if the height of the row doesn't fit on the page</span>
		<span class="token keyword">if</span> pdf<span class="token punctuation">.</span><span class="token function">GetY</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token operator">+</span>height <span class="token operator">></span> pageh<span class="token operator">-</span>mbottom <span class="token punctuation">&#123;</span>
			pdf<span class="token punctuation">.</span><span class="token function">AddPage</span><span class="token punctuation">(</span><span class="token punctuation">)</span>
			y <span class="token operator">=</span> pdf<span class="token punctuation">.</span><span class="token function">GetY</span><span class="token punctuation">(</span><span class="token punctuation">)</span>
		<span class="token punctuation">&#125;</span>
		<span class="token keyword">for</span> i<span class="token punctuation">,</span> txt <span class="token operator">:=</span> <span class="token keyword">range</span> row <span class="token punctuation">&#123;</span>
			width <span class="token operator">:=</span> cols<span class="token punctuation">[</span>i<span class="token punctuation">]</span>
			pdf<span class="token punctuation">.</span><span class="token function">Rect</span><span class="token punctuation">(</span>x<span class="token punctuation">,</span> y<span class="token punctuation">,</span> width<span class="token punctuation">,</span> height<span class="token punctuation">,</span> <span class="token string">""</span><span class="token punctuation">)</span>
			pdf<span class="token punctuation">.</span><span class="token function">MultiCell</span><span class="token punctuation">(</span>width<span class="token punctuation">,</span> lineHt<span class="token operator">+</span>marginCell<span class="token punctuation">,</span> txt<span class="token punctuation">,</span> <span class="token string">""</span><span class="token punctuation">,</span> <span class="token string">""</span><span class="token punctuation">,</span> <span class="token boolean">false</span><span class="token punctuation">)</span>
			x <span class="token operator">+=</span> width
			pdf<span class="token punctuation">.</span><span class="token function">SetXY</span><span class="token punctuation">(</span>x<span class="token punctuation">,</span> y<span class="token punctuation">)</span>
		<span class="token punctuation">&#125;</span>
		pdf<span class="token punctuation">.</span><span class="token function">SetXY</span><span class="token punctuation">(</span>curx<span class="token punctuation">,</span> y<span class="token operator">+</span>height<span class="token punctuation">)</span>
	<span class="token punctuation">&#125;</span>
	fileStr <span class="token operator">:=</span> example<span class="token punctuation">.</span><span class="token function">Filename</span><span class="token punctuation">(</span><span class="token string">"Fpdf_WrappedTableCells"</span><span class="token punctuation">)</span>
	err <span class="token operator">:=</span> pdf<span class="token punctuation">.</span><span class="token function">OutputFileAndClose</span><span class="token punctuation">(</span>fileStr<span class="token punctuation">)</span>
	example<span class="token punctuation">.</span><span class="token function">Summary</span><span class="token punctuation">(</span>err<span class="token punctuation">,</span> fileStr<span class="token punctuation">)</span>
	<span class="token comment">// Output:</span>
	<span class="token comment">// Successfully generated pdf/Fpdf_WrappedTableCells.pdf</span>
<span class="token punctuation">&#125;</span></code></pre>

<h2 id="演示在文档中包含JavaScript"><a href="#演示在文档中包含JavaScript" class="headerlink" title="演示在文档中包含JavaScript"></a>演示在文档中包含JavaScript</h2><pre class="language-go" data-language="go"><code class="language-go"><span class="token comment">// ExampleFpdf_SetJavascript demonstrates including JavaScript in the document.</span>
<span class="token keyword">func</span> <span class="token function">ExampleFpdf_SetJavascript</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">&#123;</span>
	pdf <span class="token operator">:=</span> gofpdf<span class="token punctuation">.</span><span class="token function">New</span><span class="token punctuation">(</span><span class="token string">"P"</span><span class="token punctuation">,</span> <span class="token string">"mm"</span><span class="token punctuation">,</span> <span class="token string">"A4"</span><span class="token punctuation">,</span> <span class="token string">""</span><span class="token punctuation">)</span>
	pdf<span class="token punctuation">.</span><span class="token function">SetJavascript</span><span class="token punctuation">(</span><span class="token string">"print(true);"</span><span class="token punctuation">)</span>
	pdf<span class="token punctuation">.</span><span class="token function">AddPage</span><span class="token punctuation">(</span><span class="token punctuation">)</span>
	pdf<span class="token punctuation">.</span><span class="token function">SetFont</span><span class="token punctuation">(</span><span class="token string">"Arial"</span><span class="token punctuation">,</span> <span class="token string">""</span><span class="token punctuation">,</span> <span class="token number">12</span><span class="token punctuation">)</span>
	pdf<span class="token punctuation">.</span><span class="token function">Write</span><span class="token punctuation">(</span><span class="token number">10</span><span class="token punctuation">,</span> <span class="token string">"Auto-print."</span><span class="token punctuation">)</span>
	fileStr <span class="token operator">:=</span> example<span class="token punctuation">.</span><span class="token function">Filename</span><span class="token punctuation">(</span><span class="token string">"Fpdf_SetJavascript"</span><span class="token punctuation">)</span>
	err <span class="token operator">:=</span> pdf<span class="token punctuation">.</span><span class="token function">OutputFileAndClose</span><span class="token punctuation">(</span>fileStr<span class="token punctuation">)</span>
	example<span class="token punctuation">.</span><span class="token function">Summary</span><span class="token punctuation">(</span>err<span class="token punctuation">,</span> fileStr<span class="token punctuation">)</span>
	<span class="token comment">// Output:</span>
	<span class="token comment">// Successfully generated pdf/Fpdf_SetJavascript.pdf</span>
<span class="token punctuation">&#125;</span></code></pre>

<h2 id="演示专色的使用"><a href="#演示专色的使用" class="headerlink" title="演示专色的使用"></a>演示专色的使用</h2><pre class="language-go" data-language="go"><code class="language-go"><span class="token comment">// ExampleFpdf_AddSpotColor demonstrates spot color use</span>
<span class="token keyword">func</span> <span class="token function">ExampleFpdf_AddSpotColor</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">&#123;</span>
	pdf <span class="token operator">:=</span> gofpdf<span class="token punctuation">.</span><span class="token function">New</span><span class="token punctuation">(</span><span class="token string">"P"</span><span class="token punctuation">,</span> <span class="token string">"mm"</span><span class="token punctuation">,</span> <span class="token string">"A4"</span><span class="token punctuation">,</span> <span class="token string">""</span><span class="token punctuation">)</span>
	pdf<span class="token punctuation">.</span><span class="token function">AddSpotColor</span><span class="token punctuation">(</span><span class="token string">"PANTONE 145 CVC"</span><span class="token punctuation">,</span> <span class="token number">0</span><span class="token punctuation">,</span> <span class="token number">42</span><span class="token punctuation">,</span> <span class="token number">100</span><span class="token punctuation">,</span> <span class="token number">25</span><span class="token punctuation">)</span>
	pdf<span class="token punctuation">.</span><span class="token function">AddPage</span><span class="token punctuation">(</span><span class="token punctuation">)</span>
	pdf<span class="token punctuation">.</span><span class="token function">SetFillSpotColor</span><span class="token punctuation">(</span><span class="token string">"PANTONE 145 CVC"</span><span class="token punctuation">,</span> <span class="token number">90</span><span class="token punctuation">)</span>
	pdf<span class="token punctuation">.</span><span class="token function">Rect</span><span class="token punctuation">(</span><span class="token number">80</span><span class="token punctuation">,</span> <span class="token number">40</span><span class="token punctuation">,</span> <span class="token number">50</span><span class="token punctuation">,</span> <span class="token number">50</span><span class="token punctuation">,</span> <span class="token string">"F"</span><span class="token punctuation">)</span>
	fileStr <span class="token operator">:=</span> example<span class="token punctuation">.</span><span class="token function">Filename</span><span class="token punctuation">(</span><span class="token string">"Fpdf_AddSpotColor"</span><span class="token punctuation">)</span>
	err <span class="token operator">:=</span> pdf<span class="token punctuation">.</span><span class="token function">OutputFileAndClose</span><span class="token punctuation">(</span>fileStr<span class="token punctuation">)</span>
	example<span class="token punctuation">.</span><span class="token function">Summary</span><span class="token punctuation">(</span>err<span class="token punctuation">,</span> fileStr<span class="token punctuation">)</span>
	<span class="token comment">// Output:</span>
	<span class="token comment">// Successfully generated pdf/Fpdf_AddSpotColor.pdf</span>
<span class="token punctuation">&#125;</span></code></pre>

<h2 id="演示如何使用’-RegisterAlias-‘创建目录表"><a href="#演示如何使用’-RegisterAlias-‘创建目录表" class="headerlink" title="演示如何使用’ RegisterAlias ‘创建目录表"></a>演示如何使用’ RegisterAlias ‘创建目录表</h2><pre class="language-go" data-language="go"><code class="language-go"><span class="token comment">// ExampleFpdf_RegisterAlias demonstrates how to use `RegisterAlias` to create a table of</span>
<span class="token comment">// contents.</span>
<span class="token keyword">func</span> <span class="token function">ExampleFpdf_RegisterAlias</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">&#123;</span>
	pdf <span class="token operator">:=</span> gofpdf<span class="token punctuation">.</span><span class="token function">New</span><span class="token punctuation">(</span><span class="token string">"P"</span><span class="token punctuation">,</span> <span class="token string">"mm"</span><span class="token punctuation">,</span> <span class="token string">"A4"</span><span class="token punctuation">,</span> <span class="token string">""</span><span class="token punctuation">)</span>
	pdf<span class="token punctuation">.</span><span class="token function">SetFont</span><span class="token punctuation">(</span><span class="token string">"Arial"</span><span class="token punctuation">,</span> <span class="token string">""</span><span class="token punctuation">,</span> <span class="token number">12</span><span class="token punctuation">)</span>
	pdf<span class="token punctuation">.</span><span class="token function">AliasNbPages</span><span class="token punctuation">(</span><span class="token string">""</span><span class="token punctuation">)</span>
	pdf<span class="token punctuation">.</span><span class="token function">AddPage</span><span class="token punctuation">(</span><span class="token punctuation">)</span>

	<span class="token comment">// Write the table of contents. We use aliases instead of the page number</span>
	<span class="token comment">// because we don't know which page the section will begin on.</span>
	numSections <span class="token operator">:=</span> <span class="token number">3</span>
	<span class="token keyword">for</span> i <span class="token operator">:=</span> <span class="token number">1</span><span class="token punctuation">;</span> i <span class="token operator">&lt;=</span> numSections<span class="token punctuation">;</span> i<span class="token operator">++</span> <span class="token punctuation">&#123;</span>
		pdf<span class="token punctuation">.</span><span class="token function">Cell</span><span class="token punctuation">(</span><span class="token number">0</span><span class="token punctuation">,</span> <span class="token number">10</span><span class="token punctuation">,</span> fmt<span class="token punctuation">.</span><span class="token function">Sprintf</span><span class="token punctuation">(</span><span class="token string">"Section %d begins on page &#123;mark %d&#125;"</span><span class="token punctuation">,</span> i<span class="token punctuation">,</span> i<span class="token punctuation">)</span><span class="token punctuation">)</span>
		pdf<span class="token punctuation">.</span><span class="token function">Ln</span><span class="token punctuation">(</span><span class="token number">10</span><span class="token punctuation">)</span>
	<span class="token punctuation">&#125;</span>

	<span class="token comment">// Write the sections. Before we start writing, we use `RegisterAlias` to</span>
	<span class="token comment">// ensure that the alias written in the table of contents will be replaced</span>
	<span class="token comment">// by the current page number.</span>
	<span class="token keyword">for</span> i <span class="token operator">:=</span> <span class="token number">1</span><span class="token punctuation">;</span> i <span class="token operator">&lt;=</span> numSections<span class="token punctuation">;</span> i<span class="token operator">++</span> <span class="token punctuation">&#123;</span>
		pdf<span class="token punctuation">.</span><span class="token function">AddPage</span><span class="token punctuation">(</span><span class="token punctuation">)</span>
		pdf<span class="token punctuation">.</span><span class="token function">RegisterAlias</span><span class="token punctuation">(</span>fmt<span class="token punctuation">.</span><span class="token function">Sprintf</span><span class="token punctuation">(</span><span class="token string">"&#123;mark %d&#125;"</span><span class="token punctuation">,</span> i<span class="token punctuation">)</span><span class="token punctuation">,</span> fmt<span class="token punctuation">.</span><span class="token function">Sprintf</span><span class="token punctuation">(</span><span class="token string">"%d"</span><span class="token punctuation">,</span> pdf<span class="token punctuation">.</span><span class="token function">PageNo</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">)</span>
		pdf<span class="token punctuation">.</span><span class="token function">Write</span><span class="token punctuation">(</span><span class="token number">10</span><span class="token punctuation">,</span> fmt<span class="token punctuation">.</span><span class="token function">Sprintf</span><span class="token punctuation">(</span><span class="token string">"Section %d, page %d of &#123;nb&#125;"</span><span class="token punctuation">,</span> i<span class="token punctuation">,</span> pdf<span class="token punctuation">.</span><span class="token function">PageNo</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">)</span>
	<span class="token punctuation">&#125;</span>

	fileStr <span class="token operator">:=</span> example<span class="token punctuation">.</span><span class="token function">Filename</span><span class="token punctuation">(</span><span class="token string">"Fpdf_RegisterAlias"</span><span class="token punctuation">)</span>
	err <span class="token operator">:=</span> pdf<span class="token punctuation">.</span><span class="token function">OutputFileAndClose</span><span class="token punctuation">(</span>fileStr<span class="token punctuation">)</span>
	example<span class="token punctuation">.</span><span class="token function">Summary</span><span class="token punctuation">(</span>err<span class="token punctuation">,</span> fileStr<span class="token punctuation">)</span>
	<span class="token comment">// Output:</span>
	<span class="token comment">// Successfully generated pdf/Fpdf_RegisterAlias.pdf</span>
<span class="token punctuation">&#125;</span></code></pre>

<h2 id="演示如何使用’-RegisterAlias-‘创建目录表-1"><a href="#演示如何使用’-RegisterAlias-‘创建目录表-1" class="headerlink" title="演示如何使用’ RegisterAlias ‘创建目录表"></a>演示如何使用’ RegisterAlias ‘创建目录表</h2><p>这个特殊的示例演示了UTF-8别名的使用。</p>
<pre class="language-go" data-language="go"><code class="language-go"><span class="token comment">// ExampleFpdf_RegisterAlias_utf8 demonstrates how to use `RegisterAlias` to</span>
<span class="token comment">// create a table of contents. This particular example demonstrates the use of</span>
<span class="token comment">// UTF-8 aliases.</span>
<span class="token keyword">func</span> <span class="token function">ExampleFpdf_RegisterAlias_utf8</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">&#123;</span>
	pdf <span class="token operator">:=</span> gofpdf<span class="token punctuation">.</span><span class="token function">New</span><span class="token punctuation">(</span><span class="token string">"P"</span><span class="token punctuation">,</span> <span class="token string">"mm"</span><span class="token punctuation">,</span> <span class="token string">"A4"</span><span class="token punctuation">,</span> <span class="token string">""</span><span class="token punctuation">)</span>
	pdf<span class="token punctuation">.</span><span class="token function">AddUTF8Font</span><span class="token punctuation">(</span><span class="token string">"dejavu"</span><span class="token punctuation">,</span> <span class="token string">""</span><span class="token punctuation">,</span> example<span class="token punctuation">.</span><span class="token function">FontFile</span><span class="token punctuation">(</span><span class="token string">"DejaVuSansCondensed.ttf"</span><span class="token punctuation">)</span><span class="token punctuation">)</span>
	pdf<span class="token punctuation">.</span><span class="token function">SetFont</span><span class="token punctuation">(</span><span class="token string">"dejavu"</span><span class="token punctuation">,</span> <span class="token string">""</span><span class="token punctuation">,</span> <span class="token number">12</span><span class="token punctuation">)</span>
	pdf<span class="token punctuation">.</span><span class="token function">AliasNbPages</span><span class="token punctuation">(</span><span class="token string">"&#123;entute&#125;"</span><span class="token punctuation">)</span>
	pdf<span class="token punctuation">.</span><span class="token function">AddPage</span><span class="token punctuation">(</span><span class="token punctuation">)</span>

	<span class="token comment">// Write the table of contents. We use aliases instead of the page number</span>
	<span class="token comment">// because we don't know which page the section will begin on.</span>
	numSections <span class="token operator">:=</span> <span class="token number">3</span>
	<span class="token keyword">for</span> i <span class="token operator">:=</span> <span class="token number">1</span><span class="token punctuation">;</span> i <span class="token operator">&lt;=</span> numSections<span class="token punctuation">;</span> i<span class="token operator">++</span> <span class="token punctuation">&#123;</span>
		pdf<span class="token punctuation">.</span><span class="token function">Cell</span><span class="token punctuation">(</span><span class="token number">0</span><span class="token punctuation">,</span> <span class="token number">10</span><span class="token punctuation">,</span> fmt<span class="token punctuation">.</span><span class="token function">Sprintf</span><span class="token punctuation">(</span><span class="token string">"Sekcio %d komenciĝas ĉe paĝo &#123;ĉi tiu marko %d&#125;"</span><span class="token punctuation">,</span> i<span class="token punctuation">,</span> i<span class="token punctuation">)</span><span class="token punctuation">)</span>
		pdf<span class="token punctuation">.</span><span class="token function">Ln</span><span class="token punctuation">(</span><span class="token number">10</span><span class="token punctuation">)</span>
	<span class="token punctuation">&#125;</span>

	<span class="token comment">// Write the sections. Before we start writing, we use `RegisterAlias` to</span>
	<span class="token comment">// ensure that the alias written in the table of contents will be replaced</span>
	<span class="token comment">// by the current page number.</span>
	<span class="token keyword">for</span> i <span class="token operator">:=</span> <span class="token number">1</span><span class="token punctuation">;</span> i <span class="token operator">&lt;=</span> numSections<span class="token punctuation">;</span> i<span class="token operator">++</span> <span class="token punctuation">&#123;</span>
		pdf<span class="token punctuation">.</span><span class="token function">AddPage</span><span class="token punctuation">(</span><span class="token punctuation">)</span>
		pdf<span class="token punctuation">.</span><span class="token function">RegisterAlias</span><span class="token punctuation">(</span>fmt<span class="token punctuation">.</span><span class="token function">Sprintf</span><span class="token punctuation">(</span><span class="token string">"&#123;ĉi tiu marko %d&#125;"</span><span class="token punctuation">,</span> i<span class="token punctuation">)</span><span class="token punctuation">,</span> fmt<span class="token punctuation">.</span><span class="token function">Sprintf</span><span class="token punctuation">(</span><span class="token string">"%d"</span><span class="token punctuation">,</span> pdf<span class="token punctuation">.</span><span class="token function">PageNo</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">)</span>
		pdf<span class="token punctuation">.</span><span class="token function">Write</span><span class="token punctuation">(</span><span class="token number">10</span><span class="token punctuation">,</span> fmt<span class="token punctuation">.</span><span class="token function">Sprintf</span><span class="token punctuation">(</span><span class="token string">"Sekcio %d, paĝo %d de &#123;entute&#125;"</span><span class="token punctuation">,</span> i<span class="token punctuation">,</span> pdf<span class="token punctuation">.</span><span class="token function">PageNo</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">)</span>
	<span class="token punctuation">&#125;</span>

	fileStr <span class="token operator">:=</span> example<span class="token punctuation">.</span><span class="token function">Filename</span><span class="token punctuation">(</span><span class="token string">"Fpdf_RegisterAliasUTF8"</span><span class="token punctuation">)</span>
	err <span class="token operator">:=</span> pdf<span class="token punctuation">.</span><span class="token function">OutputFileAndClose</span><span class="token punctuation">(</span>fileStr<span class="token punctuation">)</span>
	example<span class="token punctuation">.</span><span class="token function">Summary</span><span class="token punctuation">(</span>err<span class="token punctuation">,</span> fileStr<span class="token punctuation">)</span>
	<span class="token comment">// Output:</span>
	<span class="token comment">// Successfully generated pdf/Fpdf_RegisterAliasUTF8.pdf</span>
<span class="token punctuation">&#125;</span></code></pre>

<h2 id="演示图形网格的生成"><a href="#演示图形网格的生成" class="headerlink" title="演示图形网格的生成"></a>演示图形网格的生成</h2><pre class="language-go" data-language="go"><code class="language-go"><span class="token comment">// ExampleNewGrid demonstrates the generation of graph grids.</span>
<span class="token keyword">func</span> <span class="token function">ExampleNewGrid</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">&#123;</span>
	pdf <span class="token operator">:=</span> gofpdf<span class="token punctuation">.</span><span class="token function">New</span><span class="token punctuation">(</span><span class="token string">"P"</span><span class="token punctuation">,</span> <span class="token string">"mm"</span><span class="token punctuation">,</span> <span class="token string">"A4"</span><span class="token punctuation">,</span> <span class="token string">""</span><span class="token punctuation">)</span>
	pdf<span class="token punctuation">.</span><span class="token function">SetFont</span><span class="token punctuation">(</span><span class="token string">"Arial"</span><span class="token punctuation">,</span> <span class="token string">""</span><span class="token punctuation">,</span> <span class="token number">12</span><span class="token punctuation">)</span>
	pdf<span class="token punctuation">.</span><span class="token function">AddPage</span><span class="token punctuation">(</span><span class="token punctuation">)</span>

	gr <span class="token operator">:=</span> gofpdf<span class="token punctuation">.</span><span class="token function">NewGrid</span><span class="token punctuation">(</span><span class="token number">13</span><span class="token punctuation">,</span> <span class="token number">10</span><span class="token punctuation">,</span> <span class="token number">187</span><span class="token punctuation">,</span> <span class="token number">130</span><span class="token punctuation">)</span>
	gr<span class="token punctuation">.</span><span class="token function">TickmarksExtentX</span><span class="token punctuation">(</span><span class="token number">0</span><span class="token punctuation">,</span> <span class="token number">10</span><span class="token punctuation">,</span> <span class="token number">4</span><span class="token punctuation">)</span>
	gr<span class="token punctuation">.</span><span class="token function">TickmarksExtentY</span><span class="token punctuation">(</span><span class="token number">0</span><span class="token punctuation">,</span> <span class="token number">10</span><span class="token punctuation">,</span> <span class="token number">3</span><span class="token punctuation">)</span>
	gr<span class="token punctuation">.</span><span class="token function">Grid</span><span class="token punctuation">(</span>pdf<span class="token punctuation">)</span>

	gr <span class="token operator">=</span> gofpdf<span class="token punctuation">.</span><span class="token function">NewGrid</span><span class="token punctuation">(</span><span class="token number">13</span><span class="token punctuation">,</span> <span class="token number">154</span><span class="token punctuation">,</span> <span class="token number">187</span><span class="token punctuation">,</span> <span class="token number">128</span><span class="token punctuation">)</span>
	gr<span class="token punctuation">.</span>XLabelRotate <span class="token operator">=</span> <span class="token boolean">true</span>
	gr<span class="token punctuation">.</span><span class="token function">TickmarksExtentX</span><span class="token punctuation">(</span><span class="token number">0</span><span class="token punctuation">,</span> <span class="token number">1</span><span class="token punctuation">,</span> <span class="token number">12</span><span class="token punctuation">)</span>
	gr<span class="token punctuation">.</span>XDiv <span class="token operator">=</span> <span class="token number">5</span>
	gr<span class="token punctuation">.</span><span class="token function">TickmarksContainY</span><span class="token punctuation">(</span><span class="token number">0</span><span class="token punctuation">,</span> <span class="token number">1.1</span><span class="token punctuation">)</span>
	gr<span class="token punctuation">.</span>YDiv <span class="token operator">=</span> <span class="token number">20</span>
	<span class="token comment">// Replace X label formatter with month abbreviation</span>
	gr<span class="token punctuation">.</span>XTickStr <span class="token operator">=</span> <span class="token keyword">func</span><span class="token punctuation">(</span>val <span class="token builtin">float64</span><span class="token punctuation">,</span> precision <span class="token builtin">int</span><span class="token punctuation">)</span> <span class="token builtin">string</span> <span class="token punctuation">&#123;</span>
		<span class="token keyword">return</span> time<span class="token punctuation">.</span><span class="token function">Month</span><span class="token punctuation">(</span>math<span class="token punctuation">.</span><span class="token function">Mod</span><span class="token punctuation">(</span>val<span class="token punctuation">,</span> <span class="token number">12</span><span class="token punctuation">)</span> <span class="token operator">+</span> <span class="token number">1</span><span class="token punctuation">)</span><span class="token punctuation">.</span><span class="token function">String</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">[</span><span class="token number">0</span><span class="token punctuation">:</span><span class="token number">3</span><span class="token punctuation">]</span>
	<span class="token punctuation">&#125;</span>
	gr<span class="token punctuation">.</span><span class="token function">Grid</span><span class="token punctuation">(</span>pdf<span class="token punctuation">)</span>
	dot <span class="token operator">:=</span> <span class="token keyword">func</span><span class="token punctuation">(</span>x<span class="token punctuation">,</span> y <span class="token builtin">float64</span><span class="token punctuation">)</span> <span class="token punctuation">&#123;</span>
		pdf<span class="token punctuation">.</span><span class="token function">Circle</span><span class="token punctuation">(</span>gr<span class="token punctuation">.</span><span class="token function">X</span><span class="token punctuation">(</span>x<span class="token punctuation">)</span><span class="token punctuation">,</span> gr<span class="token punctuation">.</span><span class="token function">Y</span><span class="token punctuation">(</span>y<span class="token punctuation">)</span><span class="token punctuation">,</span> <span class="token number">0.5</span><span class="token punctuation">,</span> <span class="token string">"F"</span><span class="token punctuation">)</span>
	<span class="token punctuation">&#125;</span>
	pts <span class="token operator">:=</span> <span class="token punctuation">[</span><span class="token punctuation">]</span><span class="token builtin">float64</span><span class="token punctuation">&#123;</span><span class="token number">0.39</span><span class="token punctuation">,</span> <span class="token number">0.457</span><span class="token punctuation">,</span> <span class="token number">0.612</span><span class="token punctuation">,</span> <span class="token number">0.84</span><span class="token punctuation">,</span> <span class="token number">0.998</span><span class="token punctuation">,</span> <span class="token number">1.037</span><span class="token punctuation">,</span> <span class="token number">1.015</span><span class="token punctuation">,</span> <span class="token number">0.918</span><span class="token punctuation">,</span> <span class="token number">0.772</span><span class="token punctuation">,</span> <span class="token number">0.659</span><span class="token punctuation">,</span> <span class="token number">0.593</span><span class="token punctuation">,</span> <span class="token number">0.164</span><span class="token punctuation">&#125;</span>
	<span class="token keyword">for</span> month<span class="token punctuation">,</span> val <span class="token operator">:=</span> <span class="token keyword">range</span> pts <span class="token punctuation">&#123;</span>
		<span class="token function">dot</span><span class="token punctuation">(</span><span class="token function">float64</span><span class="token punctuation">(</span>month<span class="token punctuation">)</span><span class="token operator">+</span><span class="token number">0.5</span><span class="token punctuation">,</span> val<span class="token punctuation">)</span>
	<span class="token punctuation">&#125;</span>
	pdf<span class="token punctuation">.</span><span class="token function">SetDrawColor</span><span class="token punctuation">(</span><span class="token number">255</span><span class="token punctuation">,</span> <span class="token number">64</span><span class="token punctuation">,</span> <span class="token number">64</span><span class="token punctuation">)</span>
	pdf<span class="token punctuation">.</span><span class="token function">SetAlpha</span><span class="token punctuation">(</span><span class="token number">0.5</span><span class="token punctuation">,</span> <span class="token string">"Normal"</span><span class="token punctuation">)</span>
	pdf<span class="token punctuation">.</span><span class="token function">SetLineWidth</span><span class="token punctuation">(</span><span class="token number">1.2</span><span class="token punctuation">)</span>
	gr<span class="token punctuation">.</span><span class="token function">Plot</span><span class="token punctuation">(</span>pdf<span class="token punctuation">,</span> <span class="token number">0.5</span><span class="token punctuation">,</span> <span class="token number">11.5</span><span class="token punctuation">,</span> <span class="token number">50</span><span class="token punctuation">,</span> <span class="token keyword">func</span><span class="token punctuation">(</span>x <span class="token builtin">float64</span><span class="token punctuation">)</span> <span class="token builtin">float64</span> <span class="token punctuation">&#123;</span>
		<span class="token comment">// http://www.xuru.org/rt/PR.asp</span>
		<span class="token keyword">return</span> <span class="token number">0.227</span> <span class="token operator">*</span> math<span class="token punctuation">.</span><span class="token function">Exp</span><span class="token punctuation">(</span><span class="token operator">-</span><span class="token number">0.0373</span><span class="token operator">*</span>x<span class="token operator">*</span>x<span class="token operator">+</span><span class="token number">0.471</span><span class="token operator">*</span>x<span class="token punctuation">)</span>
	<span class="token punctuation">&#125;</span><span class="token punctuation">)</span>
	pdf<span class="token punctuation">.</span><span class="token function">SetAlpha</span><span class="token punctuation">(</span><span class="token number">1.0</span><span class="token punctuation">,</span> <span class="token string">"Normal"</span><span class="token punctuation">)</span>
	pdf<span class="token punctuation">.</span><span class="token function">SetXY</span><span class="token punctuation">(</span>gr<span class="token punctuation">.</span><span class="token function">X</span><span class="token punctuation">(</span><span class="token number">0.5</span><span class="token punctuation">)</span><span class="token punctuation">,</span> gr<span class="token punctuation">.</span><span class="token function">Y</span><span class="token punctuation">(</span><span class="token number">1.35</span><span class="token punctuation">)</span><span class="token punctuation">)</span>
	pdf<span class="token punctuation">.</span><span class="token function">SetFontSize</span><span class="token punctuation">(</span><span class="token number">14</span><span class="token punctuation">)</span>
	pdf<span class="token punctuation">.</span><span class="token function">Write</span><span class="token punctuation">(</span><span class="token number">0</span><span class="token punctuation">,</span> <span class="token string">"Solar energy (MWh) per month, 2016"</span><span class="token punctuation">)</span>
	pdf<span class="token punctuation">.</span><span class="token function">AddPage</span><span class="token punctuation">(</span><span class="token punctuation">)</span>

	gr <span class="token operator">=</span> gofpdf<span class="token punctuation">.</span><span class="token function">NewGrid</span><span class="token punctuation">(</span><span class="token number">13</span><span class="token punctuation">,</span> <span class="token number">10</span><span class="token punctuation">,</span> <span class="token number">187</span><span class="token punctuation">,</span> <span class="token number">274</span><span class="token punctuation">)</span>
	gr<span class="token punctuation">.</span><span class="token function">TickmarksContainX</span><span class="token punctuation">(</span><span class="token number">2.3</span><span class="token punctuation">,</span> <span class="token number">3.4</span><span class="token punctuation">)</span>
	gr<span class="token punctuation">.</span><span class="token function">TickmarksContainY</span><span class="token punctuation">(</span><span class="token number">10.4</span><span class="token punctuation">,</span> <span class="token number">56.8</span><span class="token punctuation">)</span>
	gr<span class="token punctuation">.</span><span class="token function">Grid</span><span class="token punctuation">(</span>pdf<span class="token punctuation">)</span>

	fileStr <span class="token operator">:=</span> example<span class="token punctuation">.</span><span class="token function">Filename</span><span class="token punctuation">(</span><span class="token string">"Fpdf_Grid"</span><span class="token punctuation">)</span>
	err <span class="token operator">:=</span> pdf<span class="token punctuation">.</span><span class="token function">OutputFileAndClose</span><span class="token punctuation">(</span>fileStr<span class="token punctuation">)</span>
	example<span class="token punctuation">.</span><span class="token function">Summary</span><span class="token punctuation">(</span>err<span class="token punctuation">,</span> fileStr<span class="token punctuation">)</span>
	<span class="token comment">// Output:</span>
	<span class="token comment">// Successfully generated pdf/Fpdf_Grid.pdf</span>
<span class="token punctuation">&#125;</span></code></pre>

<h2 id="演示页面框的使用"><a href="#演示页面框的使用" class="headerlink" title="演示页面框的使用"></a>演示页面框的使用</h2><pre class="language-go" data-language="go"><code class="language-go"><span class="token comment">// ExampleFpdf_SetPageBox demonstrates the use of a page box</span>
<span class="token keyword">func</span> <span class="token function">ExampleFpdf_SetPageBox</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">&#123;</span>
	<span class="token comment">// pdfinfo (from http://www.xpdfreader.com) reports the following for this example:</span>
	<span class="token comment">// ~ pdfinfo -box pdf/Fpdf_PageBox.pdf</span>
	<span class="token comment">// Producer:       FPDF 1.7</span>
	<span class="token comment">// CreationDate:   Sat Jan  1 00:00:00 2000</span>
	<span class="token comment">// ModDate:   	   Sat Jan  1 00:00:00 2000</span>
	<span class="token comment">// Tagged:         no</span>
	<span class="token comment">// Form:           none</span>
	<span class="token comment">// Pages:          1</span>
	<span class="token comment">// Encrypted:      no</span>
	<span class="token comment">// Page size:      493.23 x 739.85 pts (rotated 0 degrees)</span>
	<span class="token comment">// MediaBox:           0.00     0.00   595.28   841.89</span>
	<span class="token comment">// CropBox:           51.02    51.02   544.25   790.87</span>
	<span class="token comment">// BleedBox:          51.02    51.02   544.25   790.87</span>
	<span class="token comment">// TrimBox:           51.02    51.02   544.25   790.87</span>
	<span class="token comment">// ArtBox:            51.02    51.02   544.25   790.87</span>
	<span class="token comment">// File size:      1053 bytes</span>
	<span class="token comment">// Optimized:      no</span>
	<span class="token comment">// PDF version:    1.3</span>
	<span class="token keyword">const</span> <span class="token punctuation">(</span>
		wd        <span class="token operator">=</span> <span class="token number">210</span>
		ht        <span class="token operator">=</span> <span class="token number">297</span>
		fontsize  <span class="token operator">=</span> <span class="token number">6</span>
		boxmargin <span class="token operator">=</span> <span class="token number">3</span> <span class="token operator">*</span> fontsize
	<span class="token punctuation">)</span>
	pdf <span class="token operator">:=</span> gofpdf<span class="token punctuation">.</span><span class="token function">New</span><span class="token punctuation">(</span><span class="token string">"P"</span><span class="token punctuation">,</span> <span class="token string">"mm"</span><span class="token punctuation">,</span> <span class="token string">"A4"</span><span class="token punctuation">,</span> <span class="token string">""</span><span class="token punctuation">)</span> <span class="token comment">// 210mm x 297mm</span>
	pdf<span class="token punctuation">.</span><span class="token function">SetPageBox</span><span class="token punctuation">(</span><span class="token string">"crop"</span><span class="token punctuation">,</span> boxmargin<span class="token punctuation">,</span> boxmargin<span class="token punctuation">,</span> wd<span class="token operator">-</span><span class="token number">2</span><span class="token operator">*</span>boxmargin<span class="token punctuation">,</span> ht<span class="token operator">-</span><span class="token number">2</span><span class="token operator">*</span>boxmargin<span class="token punctuation">)</span>
	pdf<span class="token punctuation">.</span><span class="token function">SetFont</span><span class="token punctuation">(</span><span class="token string">"Arial"</span><span class="token punctuation">,</span> <span class="token string">""</span><span class="token punctuation">,</span> pdf<span class="token punctuation">.</span><span class="token function">UnitToPointConvert</span><span class="token punctuation">(</span>fontsize<span class="token punctuation">)</span><span class="token punctuation">)</span>
	pdf<span class="token punctuation">.</span><span class="token function">AddPage</span><span class="token punctuation">(</span><span class="token punctuation">)</span>
	pdf<span class="token punctuation">.</span><span class="token function">MoveTo</span><span class="token punctuation">(</span>fontsize<span class="token punctuation">,</span> fontsize<span class="token punctuation">)</span>
	pdf<span class="token punctuation">.</span><span class="token function">Write</span><span class="token punctuation">(</span>fontsize<span class="token punctuation">,</span> <span class="token string">"This will be cropped from printed output"</span><span class="token punctuation">)</span>
	pdf<span class="token punctuation">.</span><span class="token function">MoveTo</span><span class="token punctuation">(</span>boxmargin<span class="token operator">+</span>fontsize<span class="token punctuation">,</span> boxmargin<span class="token operator">+</span>fontsize<span class="token punctuation">)</span>
	pdf<span class="token punctuation">.</span><span class="token function">Write</span><span class="token punctuation">(</span>fontsize<span class="token punctuation">,</span> <span class="token string">"This will be displayed in cropped output"</span><span class="token punctuation">)</span>
	fileStr <span class="token operator">:=</span> example<span class="token punctuation">.</span><span class="token function">Filename</span><span class="token punctuation">(</span><span class="token string">"Fpdf_PageBox"</span><span class="token punctuation">)</span>
	err <span class="token operator">:=</span> pdf<span class="token punctuation">.</span><span class="token function">OutputFileAndClose</span><span class="token punctuation">(</span>fileStr<span class="token punctuation">)</span>
	example<span class="token punctuation">.</span><span class="token function">Summary</span><span class="token punctuation">(</span>err<span class="token punctuation">,</span> fileStr<span class="token punctuation">)</span>
	<span class="token comment">// Output:</span>
	<span class="token comment">// Successfully generated pdf/Fpdf_PageBox.pdf</span>
<span class="token punctuation">&#125;</span></code></pre>

<h2 id="演示下标和上标文本"><a href="#演示下标和上标文本" class="headerlink" title="演示下标和上标文本"></a>演示下标和上标文本</h2><p>改编自<a target="_blank" rel="noopener" href="http://www.fpdf.org/en/script/script61.php">http://www.fpdf.org/en/script/script61.php</a></p>
<pre class="language-go" data-language="go"><code class="language-go"><span class="token comment">// ExampleFpdf_SubWrite demonstrates subscripted and superscripted text</span>
<span class="token comment">// Adapted from http://www.fpdf.org/en/script/script61.php</span>
<span class="token keyword">func</span> <span class="token function">ExampleFpdf_SubWrite</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">&#123;</span>

	<span class="token keyword">const</span> <span class="token punctuation">(</span>
		fontSize <span class="token operator">=</span> <span class="token number">12</span>
		halfX    <span class="token operator">=</span> <span class="token number">105</span>
	<span class="token punctuation">)</span>

	pdf <span class="token operator">:=</span> gofpdf<span class="token punctuation">.</span><span class="token function">New</span><span class="token punctuation">(</span><span class="token string">"P"</span><span class="token punctuation">,</span> <span class="token string">"mm"</span><span class="token punctuation">,</span> <span class="token string">"A4"</span><span class="token punctuation">,</span> <span class="token string">""</span><span class="token punctuation">)</span> <span class="token comment">// 210mm x 297mm</span>
	pdf<span class="token punctuation">.</span><span class="token function">AddPage</span><span class="token punctuation">(</span><span class="token punctuation">)</span>
	pdf<span class="token punctuation">.</span><span class="token function">SetFont</span><span class="token punctuation">(</span><span class="token string">"Arial"</span><span class="token punctuation">,</span> <span class="token string">""</span><span class="token punctuation">,</span> fontSize<span class="token punctuation">)</span>
	<span class="token boolean">_</span><span class="token punctuation">,</span> lineHt <span class="token operator">:=</span> pdf<span class="token punctuation">.</span><span class="token function">GetFontSize</span><span class="token punctuation">(</span><span class="token punctuation">)</span>

	pdf<span class="token punctuation">.</span><span class="token function">Write</span><span class="token punctuation">(</span>lineHt<span class="token punctuation">,</span> <span class="token string">"Hello World!"</span><span class="token punctuation">)</span>
	pdf<span class="token punctuation">.</span><span class="token function">SetX</span><span class="token punctuation">(</span>halfX<span class="token punctuation">)</span>
	pdf<span class="token punctuation">.</span><span class="token function">Write</span><span class="token punctuation">(</span>lineHt<span class="token punctuation">,</span> <span class="token string">"This is standard text.\n"</span><span class="token punctuation">)</span>
	pdf<span class="token punctuation">.</span><span class="token function">Ln</span><span class="token punctuation">(</span>lineHt <span class="token operator">*</span> <span class="token number">2</span><span class="token punctuation">)</span>

	pdf<span class="token punctuation">.</span><span class="token function">SubWrite</span><span class="token punctuation">(</span><span class="token number">10</span><span class="token punctuation">,</span> <span class="token string">"H"</span><span class="token punctuation">,</span> <span class="token number">33</span><span class="token punctuation">,</span> <span class="token number">0</span><span class="token punctuation">,</span> <span class="token number">0</span><span class="token punctuation">,</span> <span class="token string">""</span><span class="token punctuation">)</span>
	pdf<span class="token punctuation">.</span><span class="token function">Write</span><span class="token punctuation">(</span><span class="token number">10</span><span class="token punctuation">,</span> <span class="token string">"ello World!"</span><span class="token punctuation">)</span>
	pdf<span class="token punctuation">.</span><span class="token function">SetX</span><span class="token punctuation">(</span>halfX<span class="token punctuation">)</span>
	pdf<span class="token punctuation">.</span><span class="token function">Write</span><span class="token punctuation">(</span><span class="token number">10</span><span class="token punctuation">,</span> <span class="token string">"This is text with a capital first letter.\n"</span><span class="token punctuation">)</span>
	pdf<span class="token punctuation">.</span><span class="token function">Ln</span><span class="token punctuation">(</span>lineHt <span class="token operator">*</span> <span class="token number">2</span><span class="token punctuation">)</span>

	pdf<span class="token punctuation">.</span><span class="token function">SubWrite</span><span class="token punctuation">(</span>lineHt<span class="token punctuation">,</span> <span class="token string">"Y"</span><span class="token punctuation">,</span> <span class="token number">6</span><span class="token punctuation">,</span> <span class="token number">0</span><span class="token punctuation">,</span> <span class="token number">0</span><span class="token punctuation">,</span> <span class="token string">""</span><span class="token punctuation">)</span>
	pdf<span class="token punctuation">.</span><span class="token function">Write</span><span class="token punctuation">(</span>lineHt<span class="token punctuation">,</span> <span class="token string">"ou can also begin the sentence with a small letter. And word wrap also works if the line is too long, like this one is."</span><span class="token punctuation">)</span>
	pdf<span class="token punctuation">.</span><span class="token function">SetX</span><span class="token punctuation">(</span>halfX<span class="token punctuation">)</span>
	pdf<span class="token punctuation">.</span><span class="token function">Write</span><span class="token punctuation">(</span>lineHt<span class="token punctuation">,</span> <span class="token string">"This is text with a small first letter.\n"</span><span class="token punctuation">)</span>
	pdf<span class="token punctuation">.</span><span class="token function">Ln</span><span class="token punctuation">(</span>lineHt <span class="token operator">*</span> <span class="token number">2</span><span class="token punctuation">)</span>

	pdf<span class="token punctuation">.</span><span class="token function">Write</span><span class="token punctuation">(</span>lineHt<span class="token punctuation">,</span> <span class="token string">"The world has a lot of km"</span><span class="token punctuation">)</span>
	pdf<span class="token punctuation">.</span><span class="token function">SubWrite</span><span class="token punctuation">(</span>lineHt<span class="token punctuation">,</span> <span class="token string">"2"</span><span class="token punctuation">,</span> <span class="token number">6</span><span class="token punctuation">,</span> <span class="token number">4</span><span class="token punctuation">,</span> <span class="token number">0</span><span class="token punctuation">,</span> <span class="token string">""</span><span class="token punctuation">)</span>
	pdf<span class="token punctuation">.</span><span class="token function">SetX</span><span class="token punctuation">(</span>halfX<span class="token punctuation">)</span>
	pdf<span class="token punctuation">.</span><span class="token function">Write</span><span class="token punctuation">(</span>lineHt<span class="token punctuation">,</span> <span class="token string">"This is text with a superscripted letter.\n"</span><span class="token punctuation">)</span>
	pdf<span class="token punctuation">.</span><span class="token function">Ln</span><span class="token punctuation">(</span>lineHt <span class="token operator">*</span> <span class="token number">2</span><span class="token punctuation">)</span>

	pdf<span class="token punctuation">.</span><span class="token function">Write</span><span class="token punctuation">(</span>lineHt<span class="token punctuation">,</span> <span class="token string">"The world has a lot of H"</span><span class="token punctuation">)</span>
	pdf<span class="token punctuation">.</span><span class="token function">SubWrite</span><span class="token punctuation">(</span>lineHt<span class="token punctuation">,</span> <span class="token string">"2"</span><span class="token punctuation">,</span> <span class="token number">6</span><span class="token punctuation">,</span> <span class="token operator">-</span><span class="token number">3</span><span class="token punctuation">,</span> <span class="token number">0</span><span class="token punctuation">,</span> <span class="token string">""</span><span class="token punctuation">)</span>
	pdf<span class="token punctuation">.</span><span class="token function">Write</span><span class="token punctuation">(</span>lineHt<span class="token punctuation">,</span> <span class="token string">"O"</span><span class="token punctuation">)</span>
	pdf<span class="token punctuation">.</span><span class="token function">SetX</span><span class="token punctuation">(</span>halfX<span class="token punctuation">)</span>
	pdf<span class="token punctuation">.</span><span class="token function">Write</span><span class="token punctuation">(</span>lineHt<span class="token punctuation">,</span> <span class="token string">"This is text with a subscripted letter.\n"</span><span class="token punctuation">)</span>

	fileStr <span class="token operator">:=</span> example<span class="token punctuation">.</span><span class="token function">Filename</span><span class="token punctuation">(</span><span class="token string">"Fpdf_SubWrite"</span><span class="token punctuation">)</span>
	err <span class="token operator">:=</span> pdf<span class="token punctuation">.</span><span class="token function">OutputFileAndClose</span><span class="token punctuation">(</span>fileStr<span class="token punctuation">)</span>
	example<span class="token punctuation">.</span><span class="token function">Summary</span><span class="token punctuation">(</span>err<span class="token punctuation">,</span> fileStr<span class="token punctuation">)</span>
	<span class="token comment">// Output:</span>
	<span class="token comment">// Successfully generated pdf/Fpdf_SubWrite.pdf</span>
<span class="token punctuation">&#125;</span></code></pre>

<h2 id="演示了SetPage-方法"><a href="#演示了SetPage-方法" class="headerlink" title="演示了SetPage()方法"></a>演示了SetPage()方法</h2><p>该方法允许将内容生成延迟到添加了所有页面之后</p>
<pre class="language-go" data-language="go"><code class="language-go"><span class="token comment">// ExampleFpdf_SetPage demomstrates the SetPage() method, allowing content</span>
<span class="token comment">// generation to be deferred until all pages have been added.</span>
<span class="token keyword">func</span> <span class="token function">ExampleFpdf_SetPage</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">&#123;</span>
	rnd <span class="token operator">:=</span> rand<span class="token punctuation">.</span><span class="token function">New</span><span class="token punctuation">(</span>rand<span class="token punctuation">.</span><span class="token function">NewSource</span><span class="token punctuation">(</span><span class="token number">0</span><span class="token punctuation">)</span><span class="token punctuation">)</span> <span class="token comment">// Make reproducible documents</span>
	pdf <span class="token operator">:=</span> gofpdf<span class="token punctuation">.</span><span class="token function">New</span><span class="token punctuation">(</span><span class="token string">"L"</span><span class="token punctuation">,</span> <span class="token string">"cm"</span><span class="token punctuation">,</span> <span class="token string">"A4"</span><span class="token punctuation">,</span> <span class="token string">""</span><span class="token punctuation">)</span>
	pdf<span class="token punctuation">.</span><span class="token function">SetFont</span><span class="token punctuation">(</span><span class="token string">"Times"</span><span class="token punctuation">,</span> <span class="token string">""</span><span class="token punctuation">,</span> <span class="token number">12</span><span class="token punctuation">)</span>

	<span class="token keyword">var</span> time <span class="token punctuation">[</span><span class="token punctuation">]</span><span class="token builtin">float64</span>
	temperaturesFromSensors <span class="token operator">:=</span> <span class="token function">make</span><span class="token punctuation">(</span><span class="token punctuation">[</span><span class="token punctuation">]</span><span class="token punctuation">[</span><span class="token punctuation">]</span><span class="token builtin">float64</span><span class="token punctuation">,</span> <span class="token number">5</span><span class="token punctuation">)</span>
	maxs <span class="token operator">:=</span> <span class="token punctuation">[</span><span class="token punctuation">]</span><span class="token builtin">float64</span><span class="token punctuation">&#123;</span><span class="token number">25</span><span class="token punctuation">,</span> <span class="token number">41</span><span class="token punctuation">,</span> <span class="token number">89</span><span class="token punctuation">,</span> <span class="token number">62</span><span class="token punctuation">,</span> <span class="token number">11</span><span class="token punctuation">&#125;</span>
	<span class="token keyword">for</span> i <span class="token operator">:=</span> <span class="token keyword">range</span> temperaturesFromSensors <span class="token punctuation">&#123;</span>
		temperaturesFromSensors<span class="token punctuation">[</span>i<span class="token punctuation">]</span> <span class="token operator">=</span> <span class="token function">make</span><span class="token punctuation">(</span><span class="token punctuation">[</span><span class="token punctuation">]</span><span class="token builtin">float64</span><span class="token punctuation">,</span> <span class="token number">0</span><span class="token punctuation">)</span>
	<span class="token punctuation">&#125;</span>

	<span class="token keyword">for</span> i <span class="token operator">:=</span> <span class="token number">0.0</span><span class="token punctuation">;</span> i <span class="token operator">&lt;</span> <span class="token number">100</span><span class="token punctuation">;</span> i <span class="token operator">+=</span> <span class="token number">0.5</span> <span class="token punctuation">&#123;</span>
		time <span class="token operator">=</span> <span class="token function">append</span><span class="token punctuation">(</span>time<span class="token punctuation">,</span> i<span class="token punctuation">)</span>
		<span class="token keyword">for</span> j<span class="token punctuation">,</span> sensor <span class="token operator">:=</span> <span class="token keyword">range</span> temperaturesFromSensors <span class="token punctuation">&#123;</span>
			dataValue <span class="token operator">:=</span> rnd<span class="token punctuation">.</span><span class="token function">Float64</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token operator">*</span> maxs<span class="token punctuation">[</span>j<span class="token punctuation">]</span>
			sensor <span class="token operator">=</span> <span class="token function">append</span><span class="token punctuation">(</span>sensor<span class="token punctuation">,</span> dataValue<span class="token punctuation">)</span>
			temperaturesFromSensors<span class="token punctuation">[</span>j<span class="token punctuation">]</span> <span class="token operator">=</span> sensor
		<span class="token punctuation">&#125;</span>
	<span class="token punctuation">&#125;</span>
	<span class="token keyword">var</span> graphs <span class="token punctuation">[</span><span class="token punctuation">]</span>gofpdf<span class="token punctuation">.</span>GridType
	<span class="token keyword">var</span> pageNums <span class="token punctuation">[</span><span class="token punctuation">]</span><span class="token builtin">int</span>
	xMax <span class="token operator">:=</span> time<span class="token punctuation">[</span><span class="token function">len</span><span class="token punctuation">(</span>time<span class="token punctuation">)</span><span class="token operator">-</span><span class="token number">1</span><span class="token punctuation">]</span>
	<span class="token keyword">for</span> i <span class="token operator">:=</span> <span class="token keyword">range</span> temperaturesFromSensors <span class="token punctuation">&#123;</span>
		<span class="token comment">//Create a new page and graph for each sensor we want to graph.</span>
		pdf<span class="token punctuation">.</span><span class="token function">AddPage</span><span class="token punctuation">(</span><span class="token punctuation">)</span>
		pdf<span class="token punctuation">.</span><span class="token function">Ln</span><span class="token punctuation">(</span><span class="token number">1</span><span class="token punctuation">)</span>
		<span class="token comment">//Custom label per sensor</span>
		pdf<span class="token punctuation">.</span><span class="token function">WriteAligned</span><span class="token punctuation">(</span><span class="token number">0</span><span class="token punctuation">,</span> <span class="token number">0</span><span class="token punctuation">,</span> <span class="token string">"Temperature Sensor "</span><span class="token operator">+</span>strconv<span class="token punctuation">.</span><span class="token function">Itoa</span><span class="token punctuation">(</span>i<span class="token operator">+</span><span class="token number">1</span><span class="token punctuation">)</span><span class="token operator">+</span><span class="token string">" (C) vs Time (min)"</span><span class="token punctuation">,</span> <span class="token string">"C"</span><span class="token punctuation">)</span>
		pdf<span class="token punctuation">.</span><span class="token function">Ln</span><span class="token punctuation">(</span><span class="token number">0.5</span><span class="token punctuation">)</span>
		graph <span class="token operator">:=</span> gofpdf<span class="token punctuation">.</span><span class="token function">NewGrid</span><span class="token punctuation">(</span>pdf<span class="token punctuation">.</span><span class="token function">GetX</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">,</span> pdf<span class="token punctuation">.</span><span class="token function">GetY</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">,</span> <span class="token number">20</span><span class="token punctuation">,</span> <span class="token number">10</span><span class="token punctuation">)</span>
		graph<span class="token punctuation">.</span><span class="token function">TickmarksContainX</span><span class="token punctuation">(</span><span class="token number">0</span><span class="token punctuation">,</span> xMax<span class="token punctuation">)</span>
		<span class="token comment">//Custom Y axis</span>
		graph<span class="token punctuation">.</span><span class="token function">TickmarksContainY</span><span class="token punctuation">(</span><span class="token number">0</span><span class="token punctuation">,</span> maxs<span class="token punctuation">[</span>i<span class="token punctuation">]</span><span class="token punctuation">)</span>
		graph<span class="token punctuation">.</span><span class="token function">Grid</span><span class="token punctuation">(</span>pdf<span class="token punctuation">)</span>
		<span class="token comment">//Save references and locations.</span>
		graphs <span class="token operator">=</span> <span class="token function">append</span><span class="token punctuation">(</span>graphs<span class="token punctuation">,</span> graph<span class="token punctuation">)</span>
		pageNums <span class="token operator">=</span> <span class="token function">append</span><span class="token punctuation">(</span>pageNums<span class="token punctuation">,</span> pdf<span class="token punctuation">.</span><span class="token function">PageNo</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">)</span>
	<span class="token punctuation">&#125;</span>
	<span class="token comment">// For each X, graph the Y in each sensor.</span>
	<span class="token keyword">for</span> i<span class="token punctuation">,</span> currTime <span class="token operator">:=</span> <span class="token keyword">range</span> time <span class="token punctuation">&#123;</span>
		<span class="token keyword">for</span> j<span class="token punctuation">,</span> sensor <span class="token operator">:=</span> <span class="token keyword">range</span> temperaturesFromSensors <span class="token punctuation">&#123;</span>
			pdf<span class="token punctuation">.</span><span class="token function">SetPage</span><span class="token punctuation">(</span>pageNums<span class="token punctuation">[</span>j<span class="token punctuation">]</span><span class="token punctuation">)</span>
			graph <span class="token operator">:=</span> graphs<span class="token punctuation">[</span>j<span class="token punctuation">]</span>
			temperature <span class="token operator">:=</span> sensor<span class="token punctuation">[</span>i<span class="token punctuation">]</span>
			pdf<span class="token punctuation">.</span><span class="token function">Circle</span><span class="token punctuation">(</span>graph<span class="token punctuation">.</span><span class="token function">X</span><span class="token punctuation">(</span>currTime<span class="token punctuation">)</span><span class="token punctuation">,</span> graph<span class="token punctuation">.</span><span class="token function">Y</span><span class="token punctuation">(</span>temperature<span class="token punctuation">)</span><span class="token punctuation">,</span> <span class="token number">0.04</span><span class="token punctuation">,</span> <span class="token string">"D"</span><span class="token punctuation">)</span>
		<span class="token punctuation">&#125;</span>
	<span class="token punctuation">&#125;</span>

	fileStr <span class="token operator">:=</span> example<span class="token punctuation">.</span><span class="token function">Filename</span><span class="token punctuation">(</span><span class="token string">"Fpdf_SetPage"</span><span class="token punctuation">)</span>
	err <span class="token operator">:=</span> pdf<span class="token punctuation">.</span><span class="token function">OutputFileAndClose</span><span class="token punctuation">(</span>fileStr<span class="token punctuation">)</span>
	example<span class="token punctuation">.</span><span class="token function">Summary</span><span class="token punctuation">(</span>err<span class="token punctuation">,</span> fileStr<span class="token punctuation">)</span>
	<span class="token comment">// Output:</span>
	<span class="token comment">// Successfully generated pdf/Fpdf_SetPage.pdf</span>
<span class="token punctuation">&#125;</span></code></pre>

<h2 id="演示如何在多个转换中正确分配图形属性"><a href="#演示如何在多个转换中正确分配图形属性" class="headerlink" title="演示如何在多个转换中正确分配图形属性"></a>演示如何在多个转换中正确分配图形属性</h2><pre class="language-go" data-language="go"><code class="language-go"><span class="token comment">// ExampleFpdf_SetFillColor demonstrates how graphic attributes are properly</span>
<span class="token comment">// assigned within multiple transformations. See issue #234.</span>
<span class="token keyword">func</span> <span class="token function">ExampleFpdf_SetFillColor</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">&#123;</span>
	pdf <span class="token operator">:=</span> gofpdf<span class="token punctuation">.</span><span class="token function">New</span><span class="token punctuation">(</span><span class="token string">"P"</span><span class="token punctuation">,</span> <span class="token string">"mm"</span><span class="token punctuation">,</span> <span class="token string">"A4"</span><span class="token punctuation">,</span> <span class="token string">""</span><span class="token punctuation">)</span>

	pdf<span class="token punctuation">.</span><span class="token function">AddPage</span><span class="token punctuation">(</span><span class="token punctuation">)</span>
	pdf<span class="token punctuation">.</span><span class="token function">SetFont</span><span class="token punctuation">(</span><span class="token string">"Arial"</span><span class="token punctuation">,</span> <span class="token string">""</span><span class="token punctuation">,</span> <span class="token number">8</span><span class="token punctuation">)</span>

	draw <span class="token operator">:=</span> <span class="token keyword">func</span><span class="token punctuation">(</span>trX<span class="token punctuation">,</span> trY <span class="token builtin">float64</span><span class="token punctuation">)</span> <span class="token punctuation">&#123;</span>
		pdf<span class="token punctuation">.</span><span class="token function">TransformBegin</span><span class="token punctuation">(</span><span class="token punctuation">)</span>
		pdf<span class="token punctuation">.</span><span class="token function">TransformTranslateX</span><span class="token punctuation">(</span>trX<span class="token punctuation">)</span>
		pdf<span class="token punctuation">.</span><span class="token function">TransformTranslateY</span><span class="token punctuation">(</span>trY<span class="token punctuation">)</span>
		pdf<span class="token punctuation">.</span><span class="token function">SetLineJoinStyle</span><span class="token punctuation">(</span><span class="token string">"round"</span><span class="token punctuation">)</span>
		pdf<span class="token punctuation">.</span><span class="token function">SetLineWidth</span><span class="token punctuation">(</span><span class="token number">0.5</span><span class="token punctuation">)</span>
		pdf<span class="token punctuation">.</span><span class="token function">SetDrawColor</span><span class="token punctuation">(</span><span class="token number">128</span><span class="token punctuation">,</span> <span class="token number">64</span><span class="token punctuation">,</span> <span class="token number">0</span><span class="token punctuation">)</span>
		pdf<span class="token punctuation">.</span><span class="token function">SetFillColor</span><span class="token punctuation">(</span><span class="token number">255</span><span class="token punctuation">,</span> <span class="token number">127</span><span class="token punctuation">,</span> <span class="token number">0</span><span class="token punctuation">)</span>
		pdf<span class="token punctuation">.</span><span class="token function">SetAlpha</span><span class="token punctuation">(</span><span class="token number">0.5</span><span class="token punctuation">,</span> <span class="token string">"Normal"</span><span class="token punctuation">)</span>
		pdf<span class="token punctuation">.</span><span class="token function">SetDashPattern</span><span class="token punctuation">(</span><span class="token punctuation">[</span><span class="token punctuation">]</span><span class="token builtin">float64</span><span class="token punctuation">&#123;</span><span class="token number">5</span><span class="token punctuation">,</span> <span class="token number">10</span><span class="token punctuation">&#125;</span><span class="token punctuation">,</span> <span class="token number">0</span><span class="token punctuation">)</span>
		pdf<span class="token punctuation">.</span><span class="token function">Rect</span><span class="token punctuation">(</span><span class="token number">0</span><span class="token punctuation">,</span> <span class="token number">0</span><span class="token punctuation">,</span> <span class="token number">40</span><span class="token punctuation">,</span> <span class="token number">40</span><span class="token punctuation">,</span> <span class="token string">"FD"</span><span class="token punctuation">)</span>
		pdf<span class="token punctuation">.</span><span class="token function">SetFontSize</span><span class="token punctuation">(</span><span class="token number">12</span><span class="token punctuation">)</span>
		pdf<span class="token punctuation">.</span><span class="token function">SetXY</span><span class="token punctuation">(</span><span class="token number">5</span><span class="token punctuation">,</span> <span class="token number">5</span><span class="token punctuation">)</span>
		pdf<span class="token punctuation">.</span><span class="token function">Write</span><span class="token punctuation">(</span><span class="token number">0</span><span class="token punctuation">,</span> <span class="token string">"Test"</span><span class="token punctuation">)</span>
		pdf<span class="token punctuation">.</span><span class="token function">TransformEnd</span><span class="token punctuation">(</span><span class="token punctuation">)</span>
	<span class="token punctuation">&#125;</span>

	<span class="token function">draw</span><span class="token punctuation">(</span><span class="token number">5</span><span class="token punctuation">,</span> <span class="token number">5</span><span class="token punctuation">)</span>
	<span class="token function">draw</span><span class="token punctuation">(</span><span class="token number">50</span><span class="token punctuation">,</span> <span class="token number">50</span><span class="token punctuation">)</span>

	fileStr <span class="token operator">:=</span> example<span class="token punctuation">.</span><span class="token function">Filename</span><span class="token punctuation">(</span><span class="token string">"Fpdf_SetFillColor"</span><span class="token punctuation">)</span>
	err <span class="token operator">:=</span> pdf<span class="token punctuation">.</span><span class="token function">OutputFileAndClose</span><span class="token punctuation">(</span>fileStr<span class="token punctuation">)</span>
	example<span class="token punctuation">.</span><span class="token function">Summary</span><span class="token punctuation">(</span>err<span class="token punctuation">,</span> fileStr<span class="token punctuation">)</span>
	<span class="token comment">// Output:</span>
	<span class="token comment">// Successfully generated pdf/Fpdf_SetFillColor.pdf</span>
<span class="token punctuation">&#125;</span></code></pre>

<h2 id="演示如何旋转标题内的文本以使水印显示在每个页面上"><a href="#演示如何旋转标题内的文本以使水印显示在每个页面上" class="headerlink" title="演示如何旋转标题内的文本以使水印显示在每个页面上"></a>演示如何旋转标题内的文本以使水印显示在每个页面上</h2><pre class="language-go" data-language="go"><code class="language-go"><span class="token comment">// ExampleFpdf_TransformRotate demonstrates how to rotate text within a header</span>
<span class="token comment">// to make a watermark that appears on each page.</span>
<span class="token keyword">func</span> <span class="token function">ExampleFpdf_TransformRotate</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">&#123;</span>

	loremStr <span class="token operator">:=</span> <span class="token function">lorem</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token operator">+</span> <span class="token string">"\n\n"</span>
	pdf <span class="token operator">:=</span> gofpdf<span class="token punctuation">.</span><span class="token function">New</span><span class="token punctuation">(</span><span class="token string">"P"</span><span class="token punctuation">,</span> <span class="token string">"mm"</span><span class="token punctuation">,</span> <span class="token string">"A4"</span><span class="token punctuation">,</span> <span class="token string">""</span><span class="token punctuation">)</span>
	margin <span class="token operator">:=</span> <span class="token number">25.0</span>
	pdf<span class="token punctuation">.</span><span class="token function">SetMargins</span><span class="token punctuation">(</span>margin<span class="token punctuation">,</span> margin<span class="token punctuation">,</span> margin<span class="token punctuation">)</span>

	fontHt <span class="token operator">:=</span> <span class="token number">13.0</span>
	lineHt <span class="token operator">:=</span> pdf<span class="token punctuation">.</span><span class="token function">PointToUnitConvert</span><span class="token punctuation">(</span>fontHt<span class="token punctuation">)</span>
	markFontHt <span class="token operator">:=</span> <span class="token number">50.0</span>
	markLineHt <span class="token operator">:=</span> pdf<span class="token punctuation">.</span><span class="token function">PointToUnitConvert</span><span class="token punctuation">(</span>markFontHt<span class="token punctuation">)</span>
	markY <span class="token operator">:=</span> <span class="token punctuation">(</span><span class="token number">297.0</span> <span class="token operator">-</span> markLineHt<span class="token punctuation">)</span> <span class="token operator">/</span> <span class="token number">2.0</span>
	ctrX <span class="token operator">:=</span> <span class="token number">210.0</span> <span class="token operator">/</span> <span class="token number">2.0</span>
	ctrY <span class="token operator">:=</span> <span class="token number">297.0</span> <span class="token operator">/</span> <span class="token number">2.0</span>

	pdf<span class="token punctuation">.</span><span class="token function">SetHeaderFunc</span><span class="token punctuation">(</span><span class="token keyword">func</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">&#123;</span>
		pdf<span class="token punctuation">.</span><span class="token function">SetFont</span><span class="token punctuation">(</span><span class="token string">"Arial"</span><span class="token punctuation">,</span> <span class="token string">"B"</span><span class="token punctuation">,</span> markFontHt<span class="token punctuation">)</span>
		pdf<span class="token punctuation">.</span><span class="token function">SetTextColor</span><span class="token punctuation">(</span><span class="token number">206</span><span class="token punctuation">,</span> <span class="token number">216</span><span class="token punctuation">,</span> <span class="token number">232</span><span class="token punctuation">)</span>
		pdf<span class="token punctuation">.</span><span class="token function">SetXY</span><span class="token punctuation">(</span>margin<span class="token punctuation">,</span> markY<span class="token punctuation">)</span>
		pdf<span class="token punctuation">.</span><span class="token function">TransformBegin</span><span class="token punctuation">(</span><span class="token punctuation">)</span>
		pdf<span class="token punctuation">.</span><span class="token function">TransformRotate</span><span class="token punctuation">(</span><span class="token number">45</span><span class="token punctuation">,</span> ctrX<span class="token punctuation">,</span> ctrY<span class="token punctuation">)</span>
		pdf<span class="token punctuation">.</span><span class="token function">CellFormat</span><span class="token punctuation">(</span><span class="token number">0</span><span class="token punctuation">,</span> markLineHt<span class="token punctuation">,</span> <span class="token string">"W A T E R M A R K   D E M O"</span><span class="token punctuation">,</span> <span class="token string">""</span><span class="token punctuation">,</span> <span class="token number">0</span><span class="token punctuation">,</span> <span class="token string">"C"</span><span class="token punctuation">,</span> <span class="token boolean">false</span><span class="token punctuation">,</span> <span class="token number">0</span><span class="token punctuation">,</span> <span class="token string">""</span><span class="token punctuation">)</span>
		pdf<span class="token punctuation">.</span><span class="token function">TransformEnd</span><span class="token punctuation">(</span><span class="token punctuation">)</span>
		pdf<span class="token punctuation">.</span><span class="token function">SetXY</span><span class="token punctuation">(</span>margin<span class="token punctuation">,</span> margin<span class="token punctuation">)</span>
	<span class="token punctuation">&#125;</span><span class="token punctuation">)</span>

	pdf<span class="token punctuation">.</span><span class="token function">AddPage</span><span class="token punctuation">(</span><span class="token punctuation">)</span>
	pdf<span class="token punctuation">.</span><span class="token function">SetFont</span><span class="token punctuation">(</span><span class="token string">"Arial"</span><span class="token punctuation">,</span> <span class="token string">""</span><span class="token punctuation">,</span> <span class="token number">8</span><span class="token punctuation">)</span>
	<span class="token keyword">for</span> j <span class="token operator">:=</span> <span class="token number">0</span><span class="token punctuation">;</span> j <span class="token operator">&lt;</span> <span class="token number">25</span><span class="token punctuation">;</span> j<span class="token operator">++</span> <span class="token punctuation">&#123;</span>
		pdf<span class="token punctuation">.</span><span class="token function">MultiCell</span><span class="token punctuation">(</span><span class="token number">0</span><span class="token punctuation">,</span> lineHt<span class="token punctuation">,</span> loremStr<span class="token punctuation">,</span> <span class="token string">""</span><span class="token punctuation">,</span> <span class="token string">"L"</span><span class="token punctuation">,</span> <span class="token boolean">false</span><span class="token punctuation">)</span>
	<span class="token punctuation">&#125;</span>

	fileStr <span class="token operator">:=</span> example<span class="token punctuation">.</span><span class="token function">Filename</span><span class="token punctuation">(</span><span class="token string">"Fpdf_RotateText"</span><span class="token punctuation">)</span>
	err <span class="token operator">:=</span> pdf<span class="token punctuation">.</span><span class="token function">OutputFileAndClose</span><span class="token punctuation">(</span>fileStr<span class="token punctuation">)</span>
	example<span class="token punctuation">.</span><span class="token function">Summary</span><span class="token punctuation">(</span>err<span class="token punctuation">,</span> fileStr<span class="token punctuation">)</span>
	<span class="token comment">// Output:</span>
	<span class="token comment">// Successfully generated pdf/Fpdf_RotateText.pdf</span>
<span class="token punctuation">&#125;</span></code></pre>

<h2 id="演示如何使用utf-8模式的字体"><a href="#演示如何使用utf-8模式的字体" class="headerlink" title="演示如何使用utf-8模式的字体"></a>演示如何使用utf-8模式的字体</h2><pre class="language-go" data-language="go"><code class="language-go"><span class="token comment">// ExampleFpdf_AddUTF8Font demonstrates how use the font</span>
<span class="token comment">// with utf-8 mode</span>
<span class="token keyword">func</span> <span class="token function">ExampleFpdf_AddUTF8Font</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">&#123;</span>
	<span class="token keyword">var</span> fileStr <span class="token builtin">string</span>
	<span class="token keyword">var</span> txtStr <span class="token punctuation">[</span><span class="token punctuation">]</span><span class="token builtin">byte</span>
	<span class="token keyword">var</span> err <span class="token builtin">error</span>

	pdf <span class="token operator">:=</span> gofpdf<span class="token punctuation">.</span><span class="token function">New</span><span class="token punctuation">(</span><span class="token string">"P"</span><span class="token punctuation">,</span> <span class="token string">"mm"</span><span class="token punctuation">,</span> <span class="token string">"A4"</span><span class="token punctuation">,</span> <span class="token string">""</span><span class="token punctuation">)</span>

	pdf<span class="token punctuation">.</span><span class="token function">AddPage</span><span class="token punctuation">(</span><span class="token punctuation">)</span>

	pdf<span class="token punctuation">.</span><span class="token function">AddUTF8Font</span><span class="token punctuation">(</span><span class="token string">"dejavu"</span><span class="token punctuation">,</span> <span class="token string">""</span><span class="token punctuation">,</span> example<span class="token punctuation">.</span><span class="token function">FontFile</span><span class="token punctuation">(</span><span class="token string">"DejaVuSansCondensed.ttf"</span><span class="token punctuation">)</span><span class="token punctuation">)</span>
	pdf<span class="token punctuation">.</span><span class="token function">AddUTF8Font</span><span class="token punctuation">(</span><span class="token string">"dejavu"</span><span class="token punctuation">,</span> <span class="token string">"B"</span><span class="token punctuation">,</span> example<span class="token punctuation">.</span><span class="token function">FontFile</span><span class="token punctuation">(</span><span class="token string">"DejaVuSansCondensed-Bold.ttf"</span><span class="token punctuation">)</span><span class="token punctuation">)</span>
	pdf<span class="token punctuation">.</span><span class="token function">AddUTF8Font</span><span class="token punctuation">(</span><span class="token string">"dejavu"</span><span class="token punctuation">,</span> <span class="token string">"I"</span><span class="token punctuation">,</span> example<span class="token punctuation">.</span><span class="token function">FontFile</span><span class="token punctuation">(</span><span class="token string">"DejaVuSansCondensed-Oblique.ttf"</span><span class="token punctuation">)</span><span class="token punctuation">)</span>
	pdf<span class="token punctuation">.</span><span class="token function">AddUTF8Font</span><span class="token punctuation">(</span><span class="token string">"dejavu"</span><span class="token punctuation">,</span> <span class="token string">"BI"</span><span class="token punctuation">,</span> example<span class="token punctuation">.</span><span class="token function">FontFile</span><span class="token punctuation">(</span><span class="token string">"DejaVuSansCondensed-BoldOblique.ttf"</span><span class="token punctuation">)</span><span class="token punctuation">)</span>

	fileStr <span class="token operator">=</span> example<span class="token punctuation">.</span><span class="token function">Filename</span><span class="token punctuation">(</span><span class="token string">"Fpdf_AddUTF8Font"</span><span class="token punctuation">)</span>
	txtStr<span class="token punctuation">,</span> err <span class="token operator">=</span> ioutil<span class="token punctuation">.</span><span class="token function">ReadFile</span><span class="token punctuation">(</span>example<span class="token punctuation">.</span><span class="token function">TextFile</span><span class="token punctuation">(</span><span class="token string">"utf-8test.txt"</span><span class="token punctuation">)</span><span class="token punctuation">)</span>
	<span class="token keyword">if</span> err <span class="token operator">==</span> <span class="token boolean">nil</span> <span class="token punctuation">&#123;</span>

		pdf<span class="token punctuation">.</span><span class="token function">SetFont</span><span class="token punctuation">(</span><span class="token string">"dejavu"</span><span class="token punctuation">,</span> <span class="token string">"B"</span><span class="token punctuation">,</span> <span class="token number">17</span><span class="token punctuation">)</span>
		pdf<span class="token punctuation">.</span><span class="token function">MultiCell</span><span class="token punctuation">(</span><span class="token number">100</span><span class="token punctuation">,</span> <span class="token number">8</span><span class="token punctuation">,</span> <span class="token string">"Text in different languages :"</span><span class="token punctuation">,</span> <span class="token string">""</span><span class="token punctuation">,</span> <span class="token string">"C"</span><span class="token punctuation">,</span> <span class="token boolean">false</span><span class="token punctuation">)</span>
		pdf<span class="token punctuation">.</span><span class="token function">SetFont</span><span class="token punctuation">(</span><span class="token string">"dejavu"</span><span class="token punctuation">,</span> <span class="token string">""</span><span class="token punctuation">,</span> <span class="token number">14</span><span class="token punctuation">)</span>
		pdf<span class="token punctuation">.</span><span class="token function">MultiCell</span><span class="token punctuation">(</span><span class="token number">100</span><span class="token punctuation">,</span> <span class="token number">5</span><span class="token punctuation">,</span> <span class="token function">string</span><span class="token punctuation">(</span>txtStr<span class="token punctuation">)</span><span class="token punctuation">,</span> <span class="token string">""</span><span class="token punctuation">,</span> <span class="token string">"C"</span><span class="token punctuation">,</span> <span class="token boolean">false</span><span class="token punctuation">)</span>
		pdf<span class="token punctuation">.</span><span class="token function">Ln</span><span class="token punctuation">(</span><span class="token number">15</span><span class="token punctuation">)</span>

		txtStr<span class="token punctuation">,</span> err <span class="token operator">=</span> ioutil<span class="token punctuation">.</span><span class="token function">ReadFile</span><span class="token punctuation">(</span>example<span class="token punctuation">.</span><span class="token function">TextFile</span><span class="token punctuation">(</span><span class="token string">"utf-8test2.txt"</span><span class="token punctuation">)</span><span class="token punctuation">)</span>
		<span class="token keyword">if</span> err <span class="token operator">==</span> <span class="token boolean">nil</span> <span class="token punctuation">&#123;</span>

			pdf<span class="token punctuation">.</span><span class="token function">SetFont</span><span class="token punctuation">(</span><span class="token string">"dejavu"</span><span class="token punctuation">,</span> <span class="token string">"BI"</span><span class="token punctuation">,</span> <span class="token number">17</span><span class="token punctuation">)</span>
			pdf<span class="token punctuation">.</span><span class="token function">MultiCell</span><span class="token punctuation">(</span><span class="token number">100</span><span class="token punctuation">,</span> <span class="token number">8</span><span class="token punctuation">,</span> <span class="token string">"Greek text with alignStr = \"J\":"</span><span class="token punctuation">,</span> <span class="token string">""</span><span class="token punctuation">,</span> <span class="token string">"C"</span><span class="token punctuation">,</span> <span class="token boolean">false</span><span class="token punctuation">)</span>
			pdf<span class="token punctuation">.</span><span class="token function">SetFont</span><span class="token punctuation">(</span><span class="token string">"dejavu"</span><span class="token punctuation">,</span> <span class="token string">"I"</span><span class="token punctuation">,</span> <span class="token number">14</span><span class="token punctuation">)</span>
			pdf<span class="token punctuation">.</span><span class="token function">MultiCell</span><span class="token punctuation">(</span><span class="token number">100</span><span class="token punctuation">,</span> <span class="token number">5</span><span class="token punctuation">,</span> <span class="token function">string</span><span class="token punctuation">(</span>txtStr<span class="token punctuation">)</span><span class="token punctuation">,</span> <span class="token string">""</span><span class="token punctuation">,</span> <span class="token string">"J"</span><span class="token punctuation">,</span> <span class="token boolean">false</span><span class="token punctuation">)</span>
			err <span class="token operator">=</span> pdf<span class="token punctuation">.</span><span class="token function">OutputFileAndClose</span><span class="token punctuation">(</span>fileStr<span class="token punctuation">)</span>

		<span class="token punctuation">&#125;</span>
	<span class="token punctuation">&#125;</span>
	example<span class="token punctuation">.</span><span class="token function">Summary</span><span class="token punctuation">(</span>err<span class="token punctuation">,</span> fileStr<span class="token punctuation">)</span>
	<span class="token comment">// Output:</span>
	<span class="token comment">// Successfully generated pdf/Fpdf_AddUTF8Font.pdf</span>
<span class="token punctuation">&#125;</span></code></pre>

<h2 id="演示如何生成TrueType字体子集"><a href="#演示如何生成TrueType字体子集" class="headerlink" title="演示如何生成TrueType字体子集"></a>演示如何生成TrueType字体子集</h2><pre class="language-go" data-language="go"><code class="language-go"><span class="token comment">// ExampleUTF8CutFont demonstrates how generate a TrueType font subset.</span>
<span class="token keyword">func</span> <span class="token function">ExampleUTF8CutFont</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">&#123;</span>
	<span class="token keyword">var</span> pdfFileStr<span class="token punctuation">,</span> fullFontFileStr<span class="token punctuation">,</span> subFontFileStr <span class="token builtin">string</span>
	<span class="token keyword">var</span> subFont<span class="token punctuation">,</span> fullFont <span class="token punctuation">[</span><span class="token punctuation">]</span><span class="token builtin">byte</span>
	<span class="token keyword">var</span> err <span class="token builtin">error</span>

	pdfFileStr <span class="token operator">=</span> example<span class="token punctuation">.</span><span class="token function">Filename</span><span class="token punctuation">(</span><span class="token string">"Fpdf_UTF8CutFont"</span><span class="token punctuation">)</span>
	fullFontFileStr <span class="token operator">=</span> example<span class="token punctuation">.</span><span class="token function">FontFile</span><span class="token punctuation">(</span><span class="token string">"calligra.ttf"</span><span class="token punctuation">)</span>
	fullFont<span class="token punctuation">,</span> err <span class="token operator">=</span> ioutil<span class="token punctuation">.</span><span class="token function">ReadFile</span><span class="token punctuation">(</span>fullFontFileStr<span class="token punctuation">)</span>
	<span class="token keyword">if</span> err <span class="token operator">==</span> <span class="token boolean">nil</span> <span class="token punctuation">&#123;</span>
		subFontFileStr <span class="token operator">=</span> <span class="token string">"calligra_abcde.ttf"</span>
		subFont <span class="token operator">=</span> gofpdf<span class="token punctuation">.</span><span class="token function">UTF8CutFont</span><span class="token punctuation">(</span>fullFont<span class="token punctuation">,</span> <span class="token string">"abcde"</span><span class="token punctuation">)</span>
		err <span class="token operator">=</span> ioutil<span class="token punctuation">.</span><span class="token function">WriteFile</span><span class="token punctuation">(</span>subFontFileStr<span class="token punctuation">,</span> subFont<span class="token punctuation">,</span> <span class="token number">0600</span><span class="token punctuation">)</span>
		<span class="token keyword">if</span> err <span class="token operator">==</span> <span class="token boolean">nil</span> <span class="token punctuation">&#123;</span>
			y <span class="token operator">:=</span> <span class="token number">24.0</span>
			pdf <span class="token operator">:=</span> gofpdf<span class="token punctuation">.</span><span class="token function">New</span><span class="token punctuation">(</span><span class="token string">"P"</span><span class="token punctuation">,</span> <span class="token string">"mm"</span><span class="token punctuation">,</span> <span class="token string">"A4"</span><span class="token punctuation">,</span> <span class="token string">""</span><span class="token punctuation">)</span>
			fontHt <span class="token operator">:=</span> <span class="token number">17.0</span>
			lineHt <span class="token operator">:=</span> pdf<span class="token punctuation">.</span><span class="token function">PointConvert</span><span class="token punctuation">(</span>fontHt<span class="token punctuation">)</span>
			write <span class="token operator">:=</span> <span class="token keyword">func</span><span class="token punctuation">(</span>format <span class="token builtin">string</span><span class="token punctuation">,</span> args <span class="token operator">...</span><span class="token keyword">interface</span><span class="token punctuation">&#123;</span><span class="token punctuation">&#125;</span><span class="token punctuation">)</span> <span class="token punctuation">&#123;</span>
				pdf<span class="token punctuation">.</span><span class="token function">SetXY</span><span class="token punctuation">(</span><span class="token number">24.0</span><span class="token punctuation">,</span> y<span class="token punctuation">)</span>
				pdf<span class="token punctuation">.</span><span class="token function">Cell</span><span class="token punctuation">(</span><span class="token number">200.0</span><span class="token punctuation">,</span> lineHt<span class="token punctuation">,</span> fmt<span class="token punctuation">.</span><span class="token function">Sprintf</span><span class="token punctuation">(</span>format<span class="token punctuation">,</span> args<span class="token operator">...</span><span class="token punctuation">)</span><span class="token punctuation">)</span>
				y <span class="token operator">+=</span> lineHt
			<span class="token punctuation">&#125;</span>
			writeSize <span class="token operator">:=</span> <span class="token keyword">func</span><span class="token punctuation">(</span>fileStr <span class="token builtin">string</span><span class="token punctuation">)</span> <span class="token punctuation">&#123;</span>
				<span class="token keyword">var</span> info os<span class="token punctuation">.</span>FileInfo
				<span class="token keyword">var</span> err <span class="token builtin">error</span>
				info<span class="token punctuation">,</span> err <span class="token operator">=</span> os<span class="token punctuation">.</span><span class="token function">Stat</span><span class="token punctuation">(</span>fileStr<span class="token punctuation">)</span>
				<span class="token keyword">if</span> err <span class="token operator">==</span> <span class="token boolean">nil</span> <span class="token punctuation">&#123;</span>
					<span class="token function">write</span><span class="token punctuation">(</span><span class="token string">"%6d: size of %s"</span><span class="token punctuation">,</span> info<span class="token punctuation">.</span><span class="token function">Size</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">,</span> fileStr<span class="token punctuation">)</span>
				<span class="token punctuation">&#125;</span>
			<span class="token punctuation">&#125;</span>
			pdf<span class="token punctuation">.</span><span class="token function">AddPage</span><span class="token punctuation">(</span><span class="token punctuation">)</span>
			pdf<span class="token punctuation">.</span><span class="token function">AddUTF8Font</span><span class="token punctuation">(</span><span class="token string">"calligra"</span><span class="token punctuation">,</span> <span class="token string">""</span><span class="token punctuation">,</span> subFontFileStr<span class="token punctuation">)</span>
			pdf<span class="token punctuation">.</span><span class="token function">SetFont</span><span class="token punctuation">(</span><span class="token string">"calligra"</span><span class="token punctuation">,</span> <span class="token string">""</span><span class="token punctuation">,</span> fontHt<span class="token punctuation">)</span>
			<span class="token function">write</span><span class="token punctuation">(</span><span class="token string">"cabbed"</span><span class="token punctuation">)</span>
			<span class="token function">write</span><span class="token punctuation">(</span><span class="token string">"vwxyz"</span><span class="token punctuation">)</span>
			pdf<span class="token punctuation">.</span><span class="token function">SetFont</span><span class="token punctuation">(</span><span class="token string">"courier"</span><span class="token punctuation">,</span> <span class="token string">""</span><span class="token punctuation">,</span> fontHt<span class="token punctuation">)</span>
			<span class="token function">writeSize</span><span class="token punctuation">(</span>fullFontFileStr<span class="token punctuation">)</span>
			<span class="token function">writeSize</span><span class="token punctuation">(</span>subFontFileStr<span class="token punctuation">)</span>
			err <span class="token operator">=</span> pdf<span class="token punctuation">.</span><span class="token function">OutputFileAndClose</span><span class="token punctuation">(</span>pdfFileStr<span class="token punctuation">)</span>
			os<span class="token punctuation">.</span><span class="token function">Remove</span><span class="token punctuation">(</span>subFontFileStr<span class="token punctuation">)</span>
		<span class="token punctuation">&#125;</span>
	<span class="token punctuation">&#125;</span>
	example<span class="token punctuation">.</span><span class="token function">Summary</span><span class="token punctuation">(</span>err<span class="token punctuation">,</span> pdfFileStr<span class="token punctuation">)</span>
	<span class="token comment">// Output:</span>
	<span class="token comment">// Successfully generated pdf/Fpdf_UTF8CutFont.pdf</span>
<span class="token punctuation">&#125;</span></code></pre>

<h2 id="演示如何调整文本下划线的厚度"><a href="#演示如何调整文本下划线的厚度" class="headerlink" title="演示如何调整文本下划线的厚度"></a>演示如何调整文本下划线的厚度</h2><pre class="language-go" data-language="go"><code class="language-go"><span class="token comment">// ExampleFpdf_SetUnderlineThickness demonstrates how to adjust the text</span>
<span class="token comment">// underline thickness.</span>
<span class="token keyword">func</span> <span class="token function">ExampleFpdf_SetUnderlineThickness</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">&#123;</span>
	pdf <span class="token operator">:=</span> gofpdf<span class="token punctuation">.</span><span class="token function">New</span><span class="token punctuation">(</span><span class="token string">"P"</span><span class="token punctuation">,</span> <span class="token string">"mm"</span><span class="token punctuation">,</span> <span class="token string">"A4"</span><span class="token punctuation">,</span> <span class="token string">""</span><span class="token punctuation">)</span> <span class="token comment">// 210mm x 297mm</span>
	pdf<span class="token punctuation">.</span><span class="token function">AddPage</span><span class="token punctuation">(</span><span class="token punctuation">)</span>
	pdf<span class="token punctuation">.</span><span class="token function">SetFont</span><span class="token punctuation">(</span><span class="token string">"Arial"</span><span class="token punctuation">,</span> <span class="token string">"U"</span><span class="token punctuation">,</span> <span class="token number">12</span><span class="token punctuation">)</span>

	pdf<span class="token punctuation">.</span><span class="token function">SetUnderlineThickness</span><span class="token punctuation">(</span><span class="token number">0.5</span><span class="token punctuation">)</span>
	pdf<span class="token punctuation">.</span><span class="token function">CellFormat</span><span class="token punctuation">(</span><span class="token number">0</span><span class="token punctuation">,</span> <span class="token number">10</span><span class="token punctuation">,</span> <span class="token string">"Thin underline"</span><span class="token punctuation">,</span> <span class="token string">""</span><span class="token punctuation">,</span> <span class="token number">1</span><span class="token punctuation">,</span> <span class="token string">""</span><span class="token punctuation">,</span> <span class="token boolean">false</span><span class="token punctuation">,</span> <span class="token number">0</span><span class="token punctuation">,</span> <span class="token string">""</span><span class="token punctuation">)</span>

	pdf<span class="token punctuation">.</span><span class="token function">SetUnderlineThickness</span><span class="token punctuation">(</span><span class="token number">1</span><span class="token punctuation">)</span>
	pdf<span class="token punctuation">.</span><span class="token function">CellFormat</span><span class="token punctuation">(</span><span class="token number">0</span><span class="token punctuation">,</span> <span class="token number">10</span><span class="token punctuation">,</span> <span class="token string">"Normal underline"</span><span class="token punctuation">,</span> <span class="token string">""</span><span class="token punctuation">,</span> <span class="token number">1</span><span class="token punctuation">,</span> <span class="token string">""</span><span class="token punctuation">,</span> <span class="token boolean">false</span><span class="token punctuation">,</span> <span class="token number">0</span><span class="token punctuation">,</span> <span class="token string">""</span><span class="token punctuation">)</span>

	pdf<span class="token punctuation">.</span><span class="token function">SetUnderlineThickness</span><span class="token punctuation">(</span><span class="token number">2</span><span class="token punctuation">)</span>
	pdf<span class="token punctuation">.</span><span class="token function">CellFormat</span><span class="token punctuation">(</span><span class="token number">0</span><span class="token punctuation">,</span> <span class="token number">10</span><span class="token punctuation">,</span> <span class="token string">"Thicker underline"</span><span class="token punctuation">,</span> <span class="token string">""</span><span class="token punctuation">,</span> <span class="token number">1</span><span class="token punctuation">,</span> <span class="token string">""</span><span class="token punctuation">,</span> <span class="token boolean">false</span><span class="token punctuation">,</span> <span class="token number">0</span><span class="token punctuation">,</span> <span class="token string">""</span><span class="token punctuation">)</span>

	fileStr <span class="token operator">:=</span> example<span class="token punctuation">.</span><span class="token function">Filename</span><span class="token punctuation">(</span><span class="token string">"Fpdf_UnderlineThickness"</span><span class="token punctuation">)</span>
	err <span class="token operator">:=</span> pdf<span class="token punctuation">.</span><span class="token function">OutputFileAndClose</span><span class="token punctuation">(</span>fileStr<span class="token punctuation">)</span>
	example<span class="token punctuation">.</span><span class="token function">Summary</span><span class="token punctuation">(</span>err<span class="token punctuation">,</span> fileStr<span class="token punctuation">)</span>
	<span class="token comment">// Output:</span>
	<span class="token comment">// Successfully generated pdf/Fpdf_UnderlineThickness.pdf</span>
<span class="token punctuation">&#125;</span></code></pre>

<h2 id="演示删除的文本"><a href="#演示删除的文本" class="headerlink" title="演示删除的文本"></a>演示删除的文本</h2><pre class="language-go" data-language="go"><code class="language-go"><span class="token comment">// ExampleFpdf_Cell_strikeout demonstrates striked-out text</span>
<span class="token keyword">func</span> <span class="token function">ExampleFpdf_Cell_strikeout</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">&#123;</span>

	pdf <span class="token operator">:=</span> gofpdf<span class="token punctuation">.</span><span class="token function">New</span><span class="token punctuation">(</span><span class="token string">"P"</span><span class="token punctuation">,</span> <span class="token string">"mm"</span><span class="token punctuation">,</span> <span class="token string">"A4"</span><span class="token punctuation">,</span> <span class="token string">""</span><span class="token punctuation">)</span> <span class="token comment">// 210mm x 297mm</span>
	pdf<span class="token punctuation">.</span><span class="token function">AddPage</span><span class="token punctuation">(</span><span class="token punctuation">)</span>

	<span class="token keyword">for</span> fontSize <span class="token operator">:=</span> <span class="token number">4</span><span class="token punctuation">;</span> fontSize <span class="token operator">&lt;</span> <span class="token number">40</span><span class="token punctuation">;</span> fontSize <span class="token operator">+=</span> <span class="token number">10</span> <span class="token punctuation">&#123;</span>
		pdf<span class="token punctuation">.</span><span class="token function">SetFont</span><span class="token punctuation">(</span><span class="token string">"Arial"</span><span class="token punctuation">,</span> <span class="token string">"S"</span><span class="token punctuation">,</span> <span class="token function">float64</span><span class="token punctuation">(</span>fontSize<span class="token punctuation">)</span><span class="token punctuation">)</span>
		pdf<span class="token punctuation">.</span><span class="token function">SetXY</span><span class="token punctuation">(</span><span class="token number">0</span><span class="token punctuation">,</span> <span class="token function">float64</span><span class="token punctuation">(</span>fontSize<span class="token punctuation">)</span><span class="token punctuation">)</span>
		pdf<span class="token punctuation">.</span><span class="token function">Cell</span><span class="token punctuation">(</span><span class="token number">40</span><span class="token punctuation">,</span> <span class="token number">10</span><span class="token punctuation">,</span> <span class="token string">"Hello World"</span><span class="token punctuation">)</span>
	<span class="token punctuation">&#125;</span>

	fileStr <span class="token operator">:=</span> example<span class="token punctuation">.</span><span class="token function">Filename</span><span class="token punctuation">(</span><span class="token string">"Fpdf_Cell_strikeout"</span><span class="token punctuation">)</span>
	err <span class="token operator">:=</span> pdf<span class="token punctuation">.</span><span class="token function">OutputFileAndClose</span><span class="token punctuation">(</span>fileStr<span class="token punctuation">)</span>
	example<span class="token punctuation">.</span><span class="token function">Summary</span><span class="token punctuation">(</span>err<span class="token punctuation">,</span> fileStr<span class="token punctuation">)</span>
	<span class="token comment">// Output:</span>
	<span class="token comment">// Successfully generated pdf/Fpdf_Cell_strikeout.pdf</span>
<span class="token punctuation">&#125;</span>
</code></pre>

<h2 id="演示pdf中的呈现模式"><a href="#演示pdf中的呈现模式" class="headerlink" title="演示pdf中的呈现模式"></a>演示pdf中的呈现模式</h2><pre class="language-go" data-language="go"><code class="language-go"><span class="token comment">// ExampleFpdf_SetTextRenderingMode demonstrates rendering modes in PDFs.</span>
<span class="token keyword">func</span> <span class="token function">ExampleFpdf_SetTextRenderingMode</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">&#123;</span>

	pdf <span class="token operator">:=</span> gofpdf<span class="token punctuation">.</span><span class="token function">New</span><span class="token punctuation">(</span><span class="token string">"P"</span><span class="token punctuation">,</span> <span class="token string">"mm"</span><span class="token punctuation">,</span> <span class="token string">"A4"</span><span class="token punctuation">,</span> <span class="token string">""</span><span class="token punctuation">)</span> <span class="token comment">// 210mm x 297mm</span>
	pdf<span class="token punctuation">.</span><span class="token function">AddPage</span><span class="token punctuation">(</span><span class="token punctuation">)</span>
	fontSz <span class="token operator">:=</span> <span class="token function">float64</span><span class="token punctuation">(</span><span class="token number">16</span><span class="token punctuation">)</span>
	lineSz <span class="token operator">:=</span> pdf<span class="token punctuation">.</span><span class="token function">PointToUnitConvert</span><span class="token punctuation">(</span>fontSz<span class="token punctuation">)</span>
	pdf<span class="token punctuation">.</span><span class="token function">SetFont</span><span class="token punctuation">(</span><span class="token string">"Times"</span><span class="token punctuation">,</span> <span class="token string">""</span><span class="token punctuation">,</span> fontSz<span class="token punctuation">)</span>
	pdf<span class="token punctuation">.</span><span class="token function">Write</span><span class="token punctuation">(</span>lineSz<span class="token punctuation">,</span> <span class="token string">"This document demonstrates various modes of text rendering. Search for \"Mode 3\" "</span><span class="token operator">+</span>
		<span class="token string">"to locate text that has been rendered invisibly. This selection can be copied "</span><span class="token operator">+</span>
		<span class="token string">"into the clipboard as usual and is useful for overlaying onto non-textual elements such "</span><span class="token operator">+</span>
		<span class="token string">"as images to make them searchable.\n\n"</span><span class="token punctuation">)</span>
	fontSz <span class="token operator">=</span> <span class="token function">float64</span><span class="token punctuation">(</span><span class="token number">125</span><span class="token punctuation">)</span>
	lineSz <span class="token operator">=</span> pdf<span class="token punctuation">.</span><span class="token function">PointToUnitConvert</span><span class="token punctuation">(</span>fontSz<span class="token punctuation">)</span>
	pdf<span class="token punctuation">.</span><span class="token function">SetFontSize</span><span class="token punctuation">(</span>fontSz<span class="token punctuation">)</span>
	pdf<span class="token punctuation">.</span><span class="token function">SetTextColor</span><span class="token punctuation">(</span><span class="token number">170</span><span class="token punctuation">,</span> <span class="token number">170</span><span class="token punctuation">,</span> <span class="token number">190</span><span class="token punctuation">)</span>
	pdf<span class="token punctuation">.</span><span class="token function">SetDrawColor</span><span class="token punctuation">(</span><span class="token number">50</span><span class="token punctuation">,</span> <span class="token number">60</span><span class="token punctuation">,</span> <span class="token number">90</span><span class="token punctuation">)</span>

	write <span class="token operator">:=</span> <span class="token keyword">func</span><span class="token punctuation">(</span>mode <span class="token builtin">int</span><span class="token punctuation">)</span> <span class="token punctuation">&#123;</span>
		pdf<span class="token punctuation">.</span><span class="token function">SetTextRenderingMode</span><span class="token punctuation">(</span>mode<span class="token punctuation">)</span>
		pdf<span class="token punctuation">.</span><span class="token function">CellFormat</span><span class="token punctuation">(</span><span class="token number">210</span><span class="token punctuation">,</span> lineSz<span class="token punctuation">,</span> fmt<span class="token punctuation">.</span><span class="token function">Sprintf</span><span class="token punctuation">(</span><span class="token string">"Mode %d"</span><span class="token punctuation">,</span> mode<span class="token punctuation">)</span><span class="token punctuation">,</span> <span class="token string">""</span><span class="token punctuation">,</span> <span class="token number">1</span><span class="token punctuation">,</span> <span class="token string">""</span><span class="token punctuation">,</span> <span class="token boolean">false</span><span class="token punctuation">,</span> <span class="token number">0</span><span class="token punctuation">,</span> <span class="token string">""</span><span class="token punctuation">)</span>
	<span class="token punctuation">&#125;</span>

	<span class="token keyword">for</span> mode <span class="token operator">:=</span> <span class="token number">0</span><span class="token punctuation">;</span> mode <span class="token operator">&lt;</span> <span class="token number">4</span><span class="token punctuation">;</span> mode<span class="token operator">++</span> <span class="token punctuation">&#123;</span>
		<span class="token function">write</span><span class="token punctuation">(</span>mode<span class="token punctuation">)</span>
	<span class="token punctuation">&#125;</span>
	<span class="token function">write</span><span class="token punctuation">(</span><span class="token number">0</span><span class="token punctuation">)</span>

	fileStr <span class="token operator">:=</span> example<span class="token punctuation">.</span><span class="token function">Filename</span><span class="token punctuation">(</span><span class="token string">"Fpdf_TextRenderingMode"</span><span class="token punctuation">)</span>
	err <span class="token operator">:=</span> pdf<span class="token punctuation">.</span><span class="token function">OutputFileAndClose</span><span class="token punctuation">(</span>fileStr<span class="token punctuation">)</span>
	example<span class="token punctuation">.</span><span class="token function">Summary</span><span class="token punctuation">(</span>err<span class="token punctuation">,</span> fileStr<span class="token punctuation">)</span>
	<span class="token comment">// Output:</span>
	<span class="token comment">// Successfully generated pdf/Fpdf_TextRenderingMode.pdf</span>
<span class="token punctuation">&#125;</span></code></pre>

<h2 id="在顶层演示了在pdf中嵌入文件"><a href="#在顶层演示了在pdf中嵌入文件" class="headerlink" title="在顶层演示了在pdf中嵌入文件"></a>在顶层演示了在pdf中嵌入文件</h2><pre class="language-go" data-language="go"><code class="language-go"><span class="token comment">// ExampleFpdf_SetTextRenderingMode demonstrates embedding files in PDFs,</span>
<span class="token comment">// at the top-level.</span>
<span class="token keyword">func</span> <span class="token function">ExampleFpdf_SetAttachments</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">&#123;</span>
	pdf <span class="token operator">:=</span> gofpdf<span class="token punctuation">.</span><span class="token function">New</span><span class="token punctuation">(</span><span class="token string">"P"</span><span class="token punctuation">,</span> <span class="token string">"mm"</span><span class="token punctuation">,</span> <span class="token string">"A4"</span><span class="token punctuation">,</span> <span class="token string">""</span><span class="token punctuation">)</span>

	<span class="token comment">// Global attachments</span>
	file<span class="token punctuation">,</span> err <span class="token operator">:=</span> ioutil<span class="token punctuation">.</span><span class="token function">ReadFile</span><span class="token punctuation">(</span><span class="token string">"grid.go"</span><span class="token punctuation">)</span>
	<span class="token keyword">if</span> err <span class="token operator">!=</span> <span class="token boolean">nil</span> <span class="token punctuation">&#123;</span>
		pdf<span class="token punctuation">.</span><span class="token function">SetError</span><span class="token punctuation">(</span>err<span class="token punctuation">)</span>
	<span class="token punctuation">&#125;</span>
	a1 <span class="token operator">:=</span> gofpdf<span class="token punctuation">.</span>Attachment<span class="token punctuation">&#123;</span>Content<span class="token punctuation">:</span> file<span class="token punctuation">,</span> Filename<span class="token punctuation">:</span> <span class="token string">"grid.go"</span><span class="token punctuation">&#125;</span>
	file<span class="token punctuation">,</span> err <span class="token operator">=</span> ioutil<span class="token punctuation">.</span><span class="token function">ReadFile</span><span class="token punctuation">(</span><span class="token string">"LICENSE"</span><span class="token punctuation">)</span>
	<span class="token keyword">if</span> err <span class="token operator">!=</span> <span class="token boolean">nil</span> <span class="token punctuation">&#123;</span>
		pdf<span class="token punctuation">.</span><span class="token function">SetError</span><span class="token punctuation">(</span>err<span class="token punctuation">)</span>
	<span class="token punctuation">&#125;</span>
	a2 <span class="token operator">:=</span> gofpdf<span class="token punctuation">.</span>Attachment<span class="token punctuation">&#123;</span>Content<span class="token punctuation">:</span> file<span class="token punctuation">,</span> Filename<span class="token punctuation">:</span> <span class="token string">"License"</span><span class="token punctuation">&#125;</span>
	pdf<span class="token punctuation">.</span><span class="token function">SetAttachments</span><span class="token punctuation">(</span><span class="token punctuation">[</span><span class="token punctuation">]</span>gofpdf<span class="token punctuation">.</span>Attachment<span class="token punctuation">&#123;</span>a1<span class="token punctuation">,</span> a2<span class="token punctuation">&#125;</span><span class="token punctuation">)</span>

	fileStr <span class="token operator">:=</span> example<span class="token punctuation">.</span><span class="token function">Filename</span><span class="token punctuation">(</span><span class="token string">"Fpdf_EmbeddedFiles"</span><span class="token punctuation">)</span>
	err <span class="token operator">=</span> pdf<span class="token punctuation">.</span><span class="token function">OutputFileAndClose</span><span class="token punctuation">(</span>fileStr<span class="token punctuation">)</span>
	example<span class="token punctuation">.</span><span class="token function">Summary</span><span class="token punctuation">(</span>err<span class="token punctuation">,</span> fileStr<span class="token punctuation">)</span>
	<span class="token comment">// Output:</span>
	<span class="token comment">// Successfully generated pdf/Fpdf_EmbeddedFiles.pdf</span>
<span class="token punctuation">&#125;</span></code></pre>

<h2 id="添加附件注释"><a href="#添加附件注释" class="headerlink" title="添加附件注释"></a>添加附件注释</h2><pre class="language-go" data-language="go"><code class="language-go"><span class="token keyword">func</span> <span class="token function">ExampleFpdf_AddAttachmentAnnotation</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">&#123;</span>
	pdf <span class="token operator">:=</span> gofpdf<span class="token punctuation">.</span><span class="token function">New</span><span class="token punctuation">(</span><span class="token string">"P"</span><span class="token punctuation">,</span> <span class="token string">"mm"</span><span class="token punctuation">,</span> <span class="token string">"A4"</span><span class="token punctuation">,</span> <span class="token string">""</span><span class="token punctuation">)</span>
	pdf<span class="token punctuation">.</span><span class="token function">SetFont</span><span class="token punctuation">(</span><span class="token string">"Arial"</span><span class="token punctuation">,</span> <span class="token string">""</span><span class="token punctuation">,</span> <span class="token number">12</span><span class="token punctuation">)</span>
	pdf<span class="token punctuation">.</span><span class="token function">AddPage</span><span class="token punctuation">(</span><span class="token punctuation">)</span>

	<span class="token comment">// Per page attachment</span>
	file<span class="token punctuation">,</span> err <span class="token operator">:=</span> ioutil<span class="token punctuation">.</span><span class="token function">ReadFile</span><span class="token punctuation">(</span><span class="token string">"grid.go"</span><span class="token punctuation">)</span>
	<span class="token keyword">if</span> err <span class="token operator">!=</span> <span class="token boolean">nil</span> <span class="token punctuation">&#123;</span>
		pdf<span class="token punctuation">.</span><span class="token function">SetError</span><span class="token punctuation">(</span>err<span class="token punctuation">)</span>
	<span class="token punctuation">&#125;</span>
	a <span class="token operator">:=</span> gofpdf<span class="token punctuation">.</span>Attachment<span class="token punctuation">&#123;</span>Content<span class="token punctuation">:</span> file<span class="token punctuation">,</span> Filename<span class="token punctuation">:</span> <span class="token string">"grid.go"</span><span class="token punctuation">,</span> Description<span class="token punctuation">:</span> <span class="token string">"Some amazing code !"</span><span class="token punctuation">&#125;</span>

	pdf<span class="token punctuation">.</span><span class="token function">SetXY</span><span class="token punctuation">(</span><span class="token number">5</span><span class="token punctuation">,</span> <span class="token number">10</span><span class="token punctuation">)</span>
	pdf<span class="token punctuation">.</span><span class="token function">Rect</span><span class="token punctuation">(</span><span class="token number">2</span><span class="token punctuation">,</span> <span class="token number">10</span><span class="token punctuation">,</span> <span class="token number">50</span><span class="token punctuation">,</span> <span class="token number">15</span><span class="token punctuation">,</span> <span class="token string">"D"</span><span class="token punctuation">)</span>
	pdf<span class="token punctuation">.</span><span class="token function">AddAttachmentAnnotation</span><span class="token punctuation">(</span><span class="token operator">&amp;</span>a<span class="token punctuation">,</span> <span class="token number">2</span><span class="token punctuation">,</span> <span class="token number">10</span><span class="token punctuation">,</span> <span class="token number">50</span><span class="token punctuation">,</span> <span class="token number">15</span><span class="token punctuation">)</span>
	pdf<span class="token punctuation">.</span><span class="token function">Cell</span><span class="token punctuation">(</span><span class="token number">50</span><span class="token punctuation">,</span> <span class="token number">15</span><span class="token punctuation">,</span> <span class="token string">"A first link"</span><span class="token punctuation">)</span>

	pdf<span class="token punctuation">.</span><span class="token function">SetXY</span><span class="token punctuation">(</span><span class="token number">5</span><span class="token punctuation">,</span> <span class="token number">80</span><span class="token punctuation">)</span>
	pdf<span class="token punctuation">.</span><span class="token function">Rect</span><span class="token punctuation">(</span><span class="token number">2</span><span class="token punctuation">,</span> <span class="token number">80</span><span class="token punctuation">,</span> <span class="token number">50</span><span class="token punctuation">,</span> <span class="token number">15</span><span class="token punctuation">,</span> <span class="token string">"D"</span><span class="token punctuation">)</span>
	pdf<span class="token punctuation">.</span><span class="token function">AddAttachmentAnnotation</span><span class="token punctuation">(</span><span class="token operator">&amp;</span>a<span class="token punctuation">,</span> <span class="token number">2</span><span class="token punctuation">,</span> <span class="token number">80</span><span class="token punctuation">,</span> <span class="token number">50</span><span class="token punctuation">,</span> <span class="token number">15</span><span class="token punctuation">)</span>
	pdf<span class="token punctuation">.</span><span class="token function">Cell</span><span class="token punctuation">(</span><span class="token number">50</span><span class="token punctuation">,</span> <span class="token number">15</span><span class="token punctuation">,</span> <span class="token string">"A second link (no copy)"</span><span class="token punctuation">)</span>

	fileStr <span class="token operator">:=</span> example<span class="token punctuation">.</span><span class="token function">Filename</span><span class="token punctuation">(</span><span class="token string">"Fpdf_FileAnnotations"</span><span class="token punctuation">)</span>
	err <span class="token operator">=</span> pdf<span class="token punctuation">.</span><span class="token function">OutputFileAndClose</span><span class="token punctuation">(</span>fileStr<span class="token punctuation">)</span>
	example<span class="token punctuation">.</span><span class="token function">Summary</span><span class="token punctuation">(</span>err<span class="token punctuation">,</span> fileStr<span class="token punctuation">)</span>
	<span class="token comment">// Output:</span>
	<span class="token comment">// Successfully generated pdf/Fpdf_FileAnnotations.pdf</span>
<span class="token punctuation">&#125;</span></code></pre>

<h2 id="设置修改日期"><a href="#设置修改日期" class="headerlink" title="设置修改日期"></a>设置修改日期</h2><pre class="language-go" data-language="go"><code class="language-go"><span class="token keyword">func</span> <span class="token function">ExampleFpdf_SetModificationDate</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">&#123;</span>
	<span class="token comment">// pdfinfo (from http://www.xpdfreader.com) reports the following for this example :</span>
	<span class="token comment">// ~ pdfinfo -box pdf/Fpdf_PageBox.pdf</span>
	<span class="token comment">// Producer:       FPDF 1.7</span>
	<span class="token comment">// CreationDate:   Sat Jan  1 00:00:00 2000</span>
	<span class="token comment">// ModDate:        Sun Jan  2 10:22:30 2000</span>
	pdf <span class="token operator">:=</span> gofpdf<span class="token punctuation">.</span><span class="token function">New</span><span class="token punctuation">(</span><span class="token string">""</span><span class="token punctuation">,</span> <span class="token string">""</span><span class="token punctuation">,</span> <span class="token string">""</span><span class="token punctuation">,</span> <span class="token string">""</span><span class="token punctuation">)</span>
	pdf<span class="token punctuation">.</span><span class="token function">AddPage</span><span class="token punctuation">(</span><span class="token punctuation">)</span>
	pdf<span class="token punctuation">.</span><span class="token function">SetModificationDate</span><span class="token punctuation">(</span>time<span class="token punctuation">.</span><span class="token function">Date</span><span class="token punctuation">(</span><span class="token number">2000</span><span class="token punctuation">,</span> <span class="token number">1</span><span class="token punctuation">,</span> <span class="token number">2</span><span class="token punctuation">,</span> <span class="token number">10</span><span class="token punctuation">,</span> <span class="token number">22</span><span class="token punctuation">,</span> <span class="token number">30</span><span class="token punctuation">,</span> <span class="token number">0</span><span class="token punctuation">,</span> time<span class="token punctuation">.</span>UTC<span class="token punctuation">)</span><span class="token punctuation">)</span>
	fileStr <span class="token operator">:=</span> example<span class="token punctuation">.</span><span class="token function">Filename</span><span class="token punctuation">(</span><span class="token string">"Fpdf_SetModificationDate"</span><span class="token punctuation">)</span>
	err <span class="token operator">:=</span> pdf<span class="token punctuation">.</span><span class="token function">OutputFileAndClose</span><span class="token punctuation">(</span>fileStr<span class="token punctuation">)</span>
	example<span class="token punctuation">.</span><span class="token function">Summary</span><span class="token punctuation">(</span>err<span class="token punctuation">,</span> fileStr<span class="token punctuation">)</span>
	<span class="token comment">// Output:</span>
	<span class="token comment">// Successfully generated pdf/Fpdf_SetModificationDate.pdf</span>
<span class="token punctuation">&#125;</span></code></pre>

                
            </div>
            <hr/>

            

    <div class="reprint" id="reprint-statement">
        
            <div class="reprint__author">
                <span class="reprint-meta" style="font-weight: bold;">
                    <i class="fas fa-user">
                        文章作者:
                    </i>
                </span>
                <span class="reprint-info">
                    <a href="/about" rel="external nofollow noreferrer">JIANG XIAOFAN</a>
                </span>
            </div>
            <div class="reprint__type">
                <span class="reprint-meta" style="font-weight: bold;">
                    <i class="fas fa-link">
                        文章链接:
                    </i>
                </span>
                <span class="reprint-info">
                    <a href="https://shuangdeyu.gitee.io/2024/01/30/gofpdf-shi-li-wen-dang/">https://shuangdeyu.gitee.io/2024/01/30/gofpdf-shi-li-wen-dang/</a>
                </span>
            </div>
            <div class="reprint__notice">
                <span class="reprint-meta" style="font-weight: bold;">
                    <i class="fas fa-copyright">
                        版权声明:
                    </i>
                </span>
                <span class="reprint-info">
                    本博客所有文章除特別声明外，均采用
                    <a href="https://creativecommons.org/licenses/by/4.0/deed.zh" rel="external nofollow noreferrer" target="_blank">CC BY 4.0</a>
                    许可协议。转载请注明来源
                    <a href="/about" target="_blank">JIANG XIAOFAN</a>
                    !
                </span>
            </div>
        
    </div>

    <script async defer>
      document.addEventListener("copy", function (e) {
        let toastHTML = '<span>复制成功，请遵循本文的转载规则</span><button class="btn-flat toast-action" onclick="navToReprintStatement()" style="font-size: smaller">查看</a>';
        M.toast({html: toastHTML})
      });

      function navToReprintStatement() {
        $("html, body").animate({scrollTop: $("#reprint-statement").offset().top - 80}, 800);
      }
    </script>



            <div class="tag_share" style="display: block;">
                <div class="post-meta__tag-list" style="display: inline-block;">
                    
                        <div class="article-tag">
                            
                                <a href="/tags/Go/">
                                    <span class="chip bg-color">Go</span>
                                </a>
                            
                                <a href="/tags/PDF/">
                                    <span class="chip bg-color">PDF</span>
                                </a>
                            
                        </div>
                    
                </div>
                <div class="post_share" style="zoom: 80%; width: fit-content; display: inline-block; float: right; margin: -0.15rem 0;">
                    <link rel="stylesheet" type="text/css" href="/libs/share/css/share.min.css">
<div id="article-share">

    
    <div class="social-share" data-sites="twitter,facebook,google,qq,qzone,wechat,weibo,douban,linkedin" data-wechat-qrcode-helper="<p>微信扫一扫即可分享！</p>"></div>
    <script src="/libs/share/js/social-share.min.js"></script>
    

    

</div>

                </div>
            </div>
            
        </div>
    </div>

    

    

    

    

    
        <style>
    .valine-card {
        margin: 1.5rem auto;
    }

    .valine-card .card-content {
        padding: 20px 20px 5px 20px;
    }

    #vcomments textarea {
        box-sizing: border-box;
        background: url("/medias/comment_bg4.jpeg") 100% 100% no-repeat;
    }

    #vcomments p {
        margin: 2px 2px 10px;
        font-size: 1.05rem;
        line-height: 1.78rem;
    }

    #vcomments blockquote p {
        text-indent: 0.2rem;
    }

    #vcomments a {
        padding: 0 2px;
        color: #4cbf30;
        font-weight: 500;
        text-decoration: none;
    }

    #vcomments img {
        max-width: 100%;
        height: auto;
        cursor: pointer;
    }

    #vcomments ol li {
        list-style-type: decimal;
    }

    #vcomments ol,
    ul {
        display: block;
        padding-left: 2em;
        word-spacing: 0.05rem;
    }

    #vcomments ul li,
    ol li {
        display: list-item;
        line-height: 1.8rem;
        font-size: 1rem;
    }

    #vcomments ul li {
        list-style-type: disc;
    }

    #vcomments ul ul li {
        list-style-type: circle;
    }

    #vcomments table, th, td {
        padding: 12px 13px;
        border: 1px solid #dfe2e5;
    }

    #vcomments table, th, td {
        border: 0;
    }

    table tr:nth-child(2n), thead {
        background-color: #fafafa;
    }

    #vcomments table th {
        background-color: #f2f2f2;
        min-width: 80px;
    }

    #vcomments table td {
        min-width: 80px;
    }

    #vcomments h1 {
        font-size: 1.85rem;
        font-weight: bold;
        line-height: 2.2rem;
    }

    #vcomments h2 {
        font-size: 1.65rem;
        font-weight: bold;
        line-height: 1.9rem;
    }

    #vcomments h3 {
        font-size: 1.45rem;
        font-weight: bold;
        line-height: 1.7rem;
    }

    #vcomments h4 {
        font-size: 1.25rem;
        font-weight: bold;
        line-height: 1.5rem;
    }

    #vcomments h5 {
        font-size: 1.1rem;
        font-weight: bold;
        line-height: 1.4rem;
    }

    #vcomments h6 {
        font-size: 1rem;
        line-height: 1.3rem;
    }

    #vcomments p {
        font-size: 1rem;
        line-height: 1.5rem;
    }

    #vcomments hr {
        margin: 12px 0;
        border: 0;
        border-top: 1px solid #ccc;
    }

    #vcomments blockquote {
        margin: 15px 0;
        border-left: 5px solid #42b983;
        padding: 1rem 0.8rem 0.3rem 0.8rem;
        color: #666;
        background-color: rgba(66, 185, 131, .1);
    }

    #vcomments pre {
        font-family: monospace, monospace;
        padding: 1.2em;
        margin: .5em 0;
        background: #272822;
        overflow: auto;
        border-radius: 0.3em;
        tab-size: 4;
    }

    #vcomments code {
        font-family: monospace, monospace;
        padding: 1px 3px;
        font-size: 0.92rem;
        color: #e96900;
        background-color: #f8f8f8;
        border-radius: 2px;
    }

    #vcomments pre code {
        font-family: monospace, monospace;
        padding: 0;
        color: #e8eaf6;
        background-color: #272822;
    }

    #vcomments pre[class*="language-"] {
        padding: 1.2em;
        margin: .5em 0;
    }

    #vcomments code[class*="language-"],
    pre[class*="language-"] {
        color: #e8eaf6;
    }

    #vcomments [type="checkbox"]:not(:checked), [type="checkbox"]:checked {
        position: inherit;
        margin-left: -1.3rem;
        margin-right: 0.4rem;
        margin-top: -1px;
        vertical-align: middle;
        left: unset;
        visibility: visible;
    }

    #vcomments b,
    strong {
        font-weight: bold;
    }

    #vcomments dfn {
        font-style: italic;
    }

    #vcomments small {
        font-size: 85%;
    }

    #vcomments cite {
        font-style: normal;
    }

    #vcomments mark {
        background-color: #fcf8e3;
        padding: .2em;
    }

    #vcomments table, th, td {
        padding: 12px 13px;
        border: 1px solid #dfe2e5;
    }

    table tr:nth-child(2n), thead {
        background-color: #fafafa;
    }

    #vcomments table th {
        background-color: #f2f2f2;
        min-width: 80px;
    }

    #vcomments table td {
        min-width: 80px;
    }

    #vcomments [type="checkbox"]:not(:checked), [type="checkbox"]:checked {
        position: inherit;
        margin-left: -1.3rem;
        margin-right: 0.4rem;
        margin-top: -1px;
        vertical-align: middle;
        left: unset;
        visibility: visible;
    }
</style>

<div class="card valine-card" data-aos="fade-up">
    <div class="comment_headling" style="font-size: 20px; font-weight: 700; position: relative; padding-left: 20px; top: 15px; padding-bottom: 5px;">
        <i class="fas fa-comments fa-fw" aria-hidden="true"></i>
        <span>评论</span>
    </div>
    <div id="vcomments" class="card-content" style="display: grid">
    </div>
</div>

<script src="/libs/valine/av-min.js"></script>
<script src="/libs/valine/Valine.min.js"></script>
<script>
    new Valine({
        el: '#vcomments',
        appId: 'Cu0yGDQXYEoC2BMFqoMyqSK1-gzGzoHsz',
        appKey: 'PYfyCYN5lI59X5Rczd5IGls5',
        notify: 'false' === 'true',
        verify: 'true' === 'true',
        visitor: 'true' === 'true',
        avatar: 'mm',
        pageSize: '20',
        lang: 'zh-cn',
        placeholder: 'hi，留个脚印吧'
    });
</script>

    

    

    

    

<article id="prenext-posts" class="prev-next articles">
    <div class="row article-row">
        
        <div class="article col s12 m6" data-aos="fade-up">
            <div class="article-badge left-badge text-color">
                <i class="fas fa-chevron-left"></i>&nbsp;上一篇</div>
            <div class="card">
                <a href="/2024/01/31/ru-he-yue-du-yi-ben-shu-bi-ji/">
                    <div class="card-image">
                        
                        <img src="/gallery/readabook.jpg" class="responsive-img" alt="《如何阅读一本书》笔记-转载">
                        
                        <span class="card-title">《如何阅读一本书》笔记-转载</span>
                    </div>
                </a>
                <div class="card-content article-content">
                    <div class="summary block-with-text">
                        
                            
                        
                    </div>
                    <div class="publish-info">
                        <span class="publish-date">
                            <i class="far fa-clock fa-fw icon-date"></i>2024-01-31
                        </span>
                        <span class="publish-author">
                            
                            <i class="fas fa-bookmark fa-fw icon-category"></i>
                            
                            <a href="/categories/%E8%AF%BB%E4%B9%A6/" class="post-category">
                                    读书
                                </a>
                            
                            
                        </span>
                    </div>
                </div>
                
                <div class="card-action article-tags">
                    
                    <a href="/tags/%E5%B7%A5%E5%85%B7%E4%B9%A6/">
                        <span class="chip bg-color">工具书</span>
                    </a>
                    
                    <a href="/tags/%E7%BB%8F%E5%85%B8/">
                        <span class="chip bg-color">经典</span>
                    </a>
                    
                </div>
                
            </div>
        </div>
        
        
        <div class="article col s12 m6" data-aos="fade-up">
            <div class="article-badge right-badge text-color">
                下一篇&nbsp;<i class="fas fa-chevron-right"></i>
            </div>
            <div class="card">
                <a href="/2024/01/19/vue-xue-xi-xiao-ji-qiao-ji-lu/">
                    <div class="card-image">
                        
                        <img src="/gallery/vue2.jpg" class="responsive-img" alt="vue学习-小技巧记录">
                        
                        <span class="card-title">vue学习-小技巧记录</span>
                    </div>
                </a>
                <div class="card-content article-content">
                    <div class="summary block-with-text">
                        
                            
                        
                    </div>
                    <div class="publish-info">
                            <span class="publish-date">
                                <i class="far fa-clock fa-fw icon-date"></i>2024-01-19
                            </span>
                        <span class="publish-author">
                            
                            <i class="fas fa-bookmark fa-fw icon-category"></i>
                            
                            <a href="/categories/%E6%8A%80%E6%9C%AF/" class="post-category">
                                    技术
                                </a>
                            
                            
                        </span>
                    </div>
                </div>
                
                <div class="card-action article-tags">
                    
                    <a href="/tags/vue/">
                        <span class="chip bg-color">vue</span>
                    </a>
                    
                </div>
                
            </div>
        </div>
        
    </div>
</article>

</div>



<!-- 代码块功能依赖 -->
<script type="text/javascript" src="/libs/codeBlock/codeBlockFuction.js"></script>

<!-- 代码语言 -->

<script type="text/javascript" src="/libs/codeBlock/codeLang.js"></script>


<!-- 代码块复制 -->

<script type="text/javascript" src="/libs/codeBlock/codeCopy.js"></script>


<!-- 代码块收缩 -->

<script type="text/javascript" src="/libs/codeBlock/codeShrink.js"></script>


    </div>
    <div id="toc-aside" class="expanded col l3 hide-on-med-and-down">
        <div class="toc-widget card" style="background-color: white;">
            <div class="toc-title"><i class="far fa-list-alt"></i>&nbsp;&nbsp;目录</div>
            <div id="toc-content"></div>
        </div>
    </div>
</div>

<!-- TOC 悬浮按钮. -->

<div id="floating-toc-btn" class="hide-on-med-and-down">
    <a class="btn-floating btn-large bg-color">
        <i class="fas fa-list-ul"></i>
    </a>
</div>


<script src="/libs/tocbot/tocbot.min.js"></script>
<script>
    $(function () {
        tocbot.init({
            tocSelector: '#toc-content',
            contentSelector: '#articleContent',
            headingsOffset: -($(window).height() * 0.4 - 45),
            collapseDepth: Number('0'),
            headingSelector: 'h2, h3, h4'
        });

        // modify the toc link href to support Chinese.
        let i = 0;
        let tocHeading = 'toc-heading-';
        $('#toc-content a').each(function () {
            $(this).attr('href', '#' + tocHeading + (++i));
        });

        // modify the heading title id to support Chinese.
        i = 0;
        $('#articleContent').children('h2, h3, h4').each(function () {
            $(this).attr('id', tocHeading + (++i));
        });

        // Set scroll toc fixed.
        let tocHeight = parseInt($(window).height() * 0.4 - 64);
        let $tocWidget = $('.toc-widget');
        $(window).scroll(function () {
            let scroll = $(window).scrollTop();
            /* add post toc fixed. */
            if (scroll > tocHeight) {
                $tocWidget.addClass('toc-fixed');
            } else {
                $tocWidget.removeClass('toc-fixed');
            }
        });

        
        /* 修复文章卡片 div 的宽度. */
        let fixPostCardWidth = function (srcId, targetId) {
            let srcDiv = $('#' + srcId);
            if (srcDiv.length === 0) {
                return;
            }

            let w = srcDiv.width();
            if (w >= 450) {
                w = w + 21;
            } else if (w >= 350 && w < 450) {
                w = w + 18;
            } else if (w >= 300 && w < 350) {
                w = w + 16;
            } else {
                w = w + 14;
            }
            $('#' + targetId).width(w);
        };

        // 切换TOC目录展开收缩的相关操作.
        const expandedClass = 'expanded';
        let $tocAside = $('#toc-aside');
        let $mainContent = $('#main-content');
        $('#floating-toc-btn .btn-floating').click(function () {
            if ($tocAside.hasClass(expandedClass)) {
                $tocAside.removeClass(expandedClass).hide();
                $mainContent.removeClass('l9');
            } else {
                $tocAside.addClass(expandedClass).show();
                $mainContent.addClass('l9');
            }
            fixPostCardWidth('artDetail', 'prenext-posts');
        });
        
    });
</script>

    

</main>




    <footer class="page-footer bg-color">
    
        <link rel="stylesheet" href="/libs/aplayer/APlayer.min.css">
<style>
    .aplayer .aplayer-lrc p {
        
        display: none;
        
        font-size: 12px;
        font-weight: 700;
        line-height: 16px !important;
    }

    .aplayer .aplayer-lrc p.aplayer-lrc-current {
        
        display: none;
        
        font-size: 15px;
        color: #42b983;
    }

    
</style>
<div class="">
    
    <div class="row">
        <meting-js class="col l8 offset-l2 m10 offset-m1 s12"
                   server="netease"
                   type="playlist"
                   id="113118807"
                   fixed='true'
                   autoplay='false'
                   theme='#42b983'
                   loop='all'
                   order='random'
                   preload='auto'
                   volume='0.7'
                   list-folded='true'
        >
        </meting-js>
    </div>
</div>

<script src="/libs/aplayer/APlayer.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/meting@2/dist/Meting.min.js"></script>

    
    <div class="container row center-align" style="margin-bottom: 0px !important;">
        <div class="col s12 m8 l8 copy-right">
            Copyright&nbsp;&copy;
            
                <span id="year">2019-2024</span>
            
            <span id="year">2019</span>
            <a href="/about" target="_blank">JIANG XIAOFAN</a>
            |&nbsp;Powered by&nbsp;<a href="https://hexo.io/" target="_blank">Hexo</a>
            |&nbsp;Theme&nbsp;<a href="https://github.com/blinkfox/hexo-theme-matery" target="_blank">Matery</a>
            <br>
            
            &nbsp;<i class="fas fa-chart-area"></i>&nbsp;站点总字数:&nbsp;<span
                class="white-color">107k</span>&nbsp;字
            
            
            
            
            
            
            <span id="busuanzi_container_site_pv">
                |&nbsp;<i class="far fa-eye"></i>&nbsp;总访问量:&nbsp;<span id="busuanzi_value_site_pv"
                    class="white-color"></span>&nbsp;次
            </span>
            
            
            <span id="busuanzi_container_site_uv">
                |&nbsp;<i class="fas fa-users"></i>&nbsp;总访问人数:&nbsp;<span id="busuanzi_value_site_uv"
                    class="white-color"></span>&nbsp;人
            </span>
            
            <br>
            
            <br>
            
        </div>
        <div class="col s12 m4 l4 social-link social-statis">
    <a href="https://github.com/blinkfox" class="tooltipped" target="_blank" data-tooltip="访问我的GitHub" data-position="top" data-delay="50">
        <i class="fab fa-github"></i>
    </a>















    <a href="/atom.xml" class="tooltipped" target="_blank" data-tooltip="RSS 订阅" data-position="top" data-delay="50">
        <i class="fas fa-rss"></i>
    </a>

</div>
    </div>
</footer>

<div class="progress-bar"></div>


    <!-- 搜索遮罩框 -->
<div id="searchModal" class="modal">
    <div class="modal-content">
        <div class="search-header">
            <span class="title"><i class="fas fa-search"></i>&nbsp;&nbsp;搜索</span>
            <input type="search" id="searchInput" name="s" placeholder="请输入搜索的关键字"
                   class="search-input">
        </div>
        <div id="searchResult"></div>
    </div>
</div>

<script type="text/javascript">
$(function () {
    var searchFunc = function (path, search_id, content_id) {
        'use strict';
        $.ajax({
            url: path,
            dataType: "xml",
            success: function (xmlResponse) {
                // get the contents from search data
                var datas = $("entry", xmlResponse).map(function () {
                    return {
                        title: $("title", this).text(),
                        content: $("content", this).text(),
                        url: $("url", this).text()
                    };
                }).get();
                var $input = document.getElementById(search_id);
                var $resultContent = document.getElementById(content_id);
                $input.addEventListener('input', function () {
                    var str = '<ul class=\"search-result-list\">';
                    var keywords = this.value.trim().toLowerCase().split(/[\s\-]+/);
                    $resultContent.innerHTML = "";
                    if (this.value.trim().length <= 0) {
                        return;
                    }
                    // perform local searching
                    datas.forEach(function (data) {
                        var isMatch = true;
                        var data_title = data.title.trim().toLowerCase();
                        var data_content = data.content.trim().replace(/<[^>]+>/g, "").toLowerCase();
                        var data_url = data.url;
                        data_url = data_url.indexOf('/') === 0 ? data.url : '/' + data_url;
                        var index_title = -1;
                        var index_content = -1;
                        var first_occur = -1;
                        // only match artiles with not empty titles and contents
                        if (data_title !== '' && data_content !== '') {
                            keywords.forEach(function (keyword, i) {
                                index_title = data_title.indexOf(keyword);
                                index_content = data_content.indexOf(keyword);
                                if (index_title < 0 && index_content < 0) {
                                    isMatch = false;
                                } else {
                                    if (index_content < 0) {
                                        index_content = 0;
                                    }
                                    if (i === 0) {
                                        first_occur = index_content;
                                    }
                                }
                            });
                        }
                        // show search results
                        if (isMatch) {
                            str += "<li><a href='" + data_url + "' class='search-result-title'>" + data_title + "</a>";
                            var content = data.content.trim().replace(/<[^>]+>/g, "");
                            if (first_occur >= 0) {
                                // cut out 100 characters
                                var start = first_occur - 20;
                                var end = first_occur + 80;
                                if (start < 0) {
                                    start = 0;
                                }
                                if (start === 0) {
                                    end = 100;
                                }
                                if (end > content.length) {
                                    end = content.length;
                                }
                                var match_content = content.substr(start, end);
                                // highlight all keywords
                                keywords.forEach(function (keyword) {
                                    var regS = new RegExp(keyword, "gi");
                                    match_content = match_content.replace(regS, "<em class=\"search-keyword\">" + keyword + "</em>");
                                });

                                str += "<p class=\"search-result\">" + match_content + "...</p>"
                            }
                            str += "</li>";
                        }
                    });
                    str += "</ul>";
                    $resultContent.innerHTML = str;
                });
            }
        });
    };

    searchFunc('/search.xml', 'searchInput', 'searchResult');
});
</script>

    <!-- 回到顶部按钮 -->
<div id="backTop" class="top-scroll">
    <a class="btn-floating btn-large waves-effect waves-light" href="#!">
        <i class="fas fa-arrow-up"></i>
    </a>
</div>


    <script src="/libs/materialize/materialize.min.js"></script>
    <script src="/libs/masonry/masonry.pkgd.min.js"></script>
    <script src="/libs/aos/aos.js"></script>
    <script src="/libs/scrollprogress/scrollProgress.min.js"></script>
    <script src="/libs/lightGallery/js/lightgallery-all.min.js"></script>
    <script src="/js/matery.js"></script>

    <!-- Baidu Analytics -->

    <!-- Baidu Push -->

<script>
    (function () {
        var bp = document.createElement('script');
        var curProtocol = window.location.protocol.split(':')[0];
        if (curProtocol === 'https') {
            bp.src = 'https://zz.bdstatic.com/linksubmit/push.js';
        } else {
            bp.src = 'http://push.zhanzhang.baidu.com/push.js';
        }
        var s = document.getElementsByTagName("script")[0];
        s.parentNode.insertBefore(bp, s);
    })();
</script>

    
    <script src="/libs/others/clicklove.js" async="async"></script>
    
    
    <script async src="/libs/others/busuanzi.pure.mini.js"></script>
    

    

    

	
    

    

    

    
    <script src="/libs/instantpage/instantpage.js" type="module"></script>
    

</body>

</html>
